Skip to content

Commit ba0e02c

Browse files
Sandeepandylibrian
authored andcommitted
modify pid capture logic and faq page link
1 parent 374b536 commit ba0e02c

File tree

2 files changed

+65
-40
lines changed

2 files changed

+65
-40
lines changed

scripts/run_yc_360.ps1

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function Start-yc360 {
1313
Set-StrictMode -Version Latest
1414

1515
# Version Info
16-
$scriptVersion = "2025.06.20.2137"
16+
$scriptVersion = "2025.07.28.1950"
1717
Write-Host "`n[INFO] Starting yc-360 installer... (Version: $scriptVersion)"
1818

1919
try {
@@ -29,13 +29,8 @@ function Start-yc360 {
2929

3030
# Download yc-360
3131
Write-Host "[INFO] Downloading yc-360..."
32-
if (Get-Command curl.exe -ErrorAction SilentlyContinue) {
33-
& curl.exe -sSL -o $zip_file $url
34-
} else {
35-
Write-Host "[INFO] 'curl' not found, using Invoke-WebRequest..."
36-
$ProgressPreference = 'SilentlyContinue'
37-
Invoke-WebRequest -Uri $url -OutFile $zip_file -UseBasicParsing
38-
}
32+
$ProgressPreference = 'SilentlyContinue'
33+
Invoke-WebRequest -Uri $url -OutFile $zip_file -UseBasicParsing
3934

4035
# Detect architecture
4136
$arch = $env:PROCESSOR_ARCHITECTURE
@@ -47,6 +42,7 @@ function Start-yc360 {
4742
"aarch64" { $arch_folder = "arm64" }
4843
default { throw "[ERROR] Unsupported architecture: $arch" }
4944
}
45+
Write-Host "[INFO] Detected platform: $platform / architecture: $arch_folder"
5046

5147
# Extract yc.exe (flat layout)
5248
Write-Host "[INFO] Extracting yc binary..."
@@ -57,6 +53,7 @@ function Start-yc360 {
5753
} else {
5854
throw "[ERROR] No extraction tool found (jar or unzip required)"
5955
}
56+
Write-Host "[INFO] yc.exe extracted to: $bin_dir\yc.exe"
6057

6158
# Move binary
6259
$target = Join-Path $work_dir "$platform\yc.exe"
@@ -69,40 +66,40 @@ function Start-yc360 {
6966
# Clean up temp folders (except output)
7067
Remove-Item -Recurse -Force "$work_dir\linux","$work_dir\mac","$work_dir\windows","$zip_file" -ErrorAction SilentlyContinue
7168

72-
# Detect JAVA_HOME
73-
if (-Not $JavaHome) {
74-
$javaCmd = Get-Command java -ErrorAction SilentlyContinue
75-
if (-not $javaCmd) {
76-
Write-Warning "[WARN] Java not found in PATH. Skipping execution."
77-
return
69+
# Set Java path if not provided
70+
if (-not $JavaHome -or $JavaHome -eq "") {
71+
$javaPath = Get-Command java -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
72+
if ($javaPath) {
73+
$JavaHome = Split-Path (Split-Path $javaPath -Parent) -Parent
74+
Write-Host "[INFO] JavaHome not provided. Using detected JavaHome: $JavaHome"
75+
} else {
76+
Write-Error "[ERROR] Java not found in PATH and JavaHome was not provided."
77+
exit 1
7878
}
79-
$javaPath = $javaCmd.Source
80-
$JavaHome = Split-Path -Parent (Split-Path -Parent $javaPath)
81-
Write-Host "[INFO] Detected JAVA_HOME: $JavaHome"
79+
} else {
80+
Write-Host "[INFO] Using provided JavaHome: $JavaHome"
8281
}
8382

84-
# Detect PIDs
85-
if (-not $TargetPids) {
86-
if (Get-Command jps -ErrorAction SilentlyContinue) {
87-
$TargetPids = (& jps | Where-Object { $_ -notmatch 'Jps' } | ForEach-Object {
88-
($_ -split '\s+')[0]
89-
}) -join ","
90-
}
91-
92-
if (-not $TargetPids) {
93-
$javaProcesses = Get-Process | Where-Object { $_.Name -like "java*" }
94-
$TargetPids = $javaProcesses.Id -join ","
95-
}
96-
97-
if (-not $TargetPids) {
98-
Write-Warning "`n[WARN] No running Java process found. Nothing to capture."
99-
return
83+
# Set PIDs if not provided
84+
if (-not $TargetPids -or $TargetPids -eq "") {
85+
$javaProcesses = Get-Process java -ErrorAction SilentlyContinue
86+
if ($javaProcesses.Count -eq 0) {
87+
Write-Error "[ERROR] No running Java processes found, and TargetPids not provided."
88+
exit 1
10089
}
90+
$TargetPids = ($javaProcesses | Select-Object -ExpandProperty Id) -join ","
91+
Write-Host "[INFO] TargetPids not provided. Using detected Java PIDs: $TargetPids"
92+
} else {
93+
Write-Host "[INFO] Using provided TargetPids: $TargetPids"
10194
}
10295

103-
# Execute yc for each PID
96+
# Print the detected PIDs
10497
$pidsArray = $TargetPids -split ','
10598

99+
Write-Host "`n[INFO] Detected the following Java PIDs to capture:"
100+
$pidsArray | ForEach-Object { Write-Host " - $_" }
101+
102+
# Execute yc for each PID
106103
foreach ($targetPid in $pidsArray) {
107104
if (-not $ExtraArgs -or $ExtraArgs.Count -eq 0) {
108105
Write-Host "[INFO] Running yc with default: -onlyCapture for PID: $targetPid"
@@ -115,10 +112,24 @@ function Start-yc360 {
115112

116113
# Final cleanup
117114
Remove-Item -Recurse -Force "$bin_dir" -ErrorAction SilentlyContinue
118-
Write-Host "`n[INFO] yc-360 run completed. Output saved in: $work_dir"
115+
116+
# Navigate to output directory and list contents
117+
Set-Location $work_dir
118+
Write-Host "`n[INFO] Listing contents of output directory:"
119+
Get-ChildItem -Force | Format-Table -AutoSize
120+
121+
# Open the output folder in File Explorer
122+
Start-Process explorer.exe $work_dir
123+
124+
Write-Host "`n[INFO] Script executed successfully."
119125

120126
} catch {
121-
Write-Warning "`n[WARN] Script encountered an error: $_"
127+
Write-Host "`n[ERROR] yc-360 script encountered an error."
128+
Write-Host "------------------------------------------------------------"
129+
Write-Host "Need help? Visit our troubleshooting FAQ page:"
130+
Write-Host "https://test.docs.ycrash.io/yc-360/faq/run-yc-360-faq.html"
131+
Write-Host "------------------------------------------------------------"
132+
Write-Host "`n[ERROR DETAILS] $($_.Exception.Message)"
122133
}
123134
}
124135

scripts/run_yc_360.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ IFS=$'\n\t'
99
trap 'echo "[ERROR] Script interrupted"; exit 1' SIGINT SIGTERM
1010
trap 'echo "[INFO] Script exited successfully."' EXIT
1111

12-
SCRIPT_VERSION="2025.06.17.2000"
12+
SCRIPT_VERSION="2025.07.28.1141"
1313
echo "[INFO] Starting yc-360 installer (version $SCRIPT_VERSION)"
1414

1515
# Setup workspace
@@ -110,9 +110,10 @@ echo "[INFO] Using JAVA_HOME: $user_java_home"
110110
# Auto-detect PIDs if not supplied
111111
if [[ -z "$user_pids" ]]; then
112112
if command -v jps >/dev/null 2>&1; then
113-
user_pids=$(jps | grep -v Jps | awk '{print $1}' | xargs || true)
113+
user_pids=$(jps | awk '$2 != "Jps" {print $1}' | xargs || true)
114114
else
115-
user_pids=$(pgrep -f 'java' | xargs || true)
115+
# Use ps to avoid catching grep or this script
116+
user_pids=$(ps -eo pid,comm,args | awk '/[j]ava/ && $2 != "grep" {print $1}' | xargs || true)
116117
fi
117118
fi
118119

@@ -143,4 +144,17 @@ done
143144

144145
# Cleanup after run
145146
rm -rf "$bin_dir" "$work_dir/$platform"
146-
echo "[INFO] yc-360 run completed. Output saved in: $work_dir"
147+
echo "[INFO] yc-360 run completed. Output saved in: $work_dir"
148+
149+
# Move into the work directory and list files
150+
cd "$work_dir"
151+
echo "[INFO] Listing contents of output directory:"
152+
ls -l
153+
154+
# Trap for any unhandled errors to show FAQ link
155+
trap 'echo "
156+
[ERROR] yc-360 script encountered an error.
157+
------------------------------------------------------------
158+
Need help? Visit our troubleshooting FAQ page:
159+
https://test.docs.ycrash.io/yc-360/faq/run-yc-360-faq.html
160+
------------------------------------------------------------" >&2' ERR

0 commit comments

Comments
 (0)