diff --git a/resources/win/atom.cmd b/resources/win/atom.cmd index d3188b3ea..c9bfdd5ba 100644 --- a/resources/win/atom.cmd +++ b/resources/win/atom.cmd @@ -1,6 +1,7 @@ @echo off SET EXPECT_OUTPUT= +SET WAIT= FOR %%a IN (%*) DO ( IF /I "%%a"=="-f" SET EXPECT_OUTPUT=YES @@ -11,13 +12,41 @@ FOR %%a IN (%*) DO ( IF /I "%%a"=="--test" SET EXPECT_OUTPUT=YES IF /I "%%a"=="-v" SET EXPECT_OUTPUT=YES IF /I "%%a"=="--version" SET EXPECT_OUTPUT=YES - IF /I "%%a"=="-w" SET EXPECT_OUTPUT=YES - IF /I "%%a"=="--wait" SET EXPECT_OUTPUT=YES + IF /I "%%a"=="-w" ( + SET EXPECT_OUTPUT=YES + SET WAIT=YES + ) + IF /I "%%a"=="--wait" ( + SET EXPECT_OUTPUT=YES + SET WAIT=YES + ) ) +rem Getting the process ID in cmd of the current cmd process: http://superuser.com/questions/881789/identify-and-kill-batch-script-started-before +set T=%TEMP%\atomCmdProcessId-%time::=%.tmp +wmic process where (Name="WMIC.exe" AND CommandLine LIKE "%%%TIME%%%") get ParentProcessId /value | find "ParentProcessId" >%T% +set /P A=<%T% +set PID=%A:~16% +del %T% + IF "%EXPECT_OUTPUT%"=="YES" ( SET ELECTRON_ENABLE_LOGGING=YES - "%~dp0\..\..\atom.exe" %* + IF "%WAIT%"=="YES" ( + "%~dp0\..\..\atom.exe" --pid=%PID% %* + rem If the wait flag is set, don't exit this process until Atom tells it to. + goto waitLoop + ) + ELSE ( + "%~dp0\..\..\atom.exe" %* + ) ) ELSE ( "%~dp0\..\app\apm\bin\node.exe" "%~dp0\atom.js" %* ) + +goto end + +:waitLoop + sleep 1 + goto waitLoop + +:end diff --git a/resources/win/atom.sh b/resources/win/atom.sh index 9e2c6da65..0eaf193c0 100644 --- a/resources/win/atom.sh +++ b/resources/win/atom.sh @@ -4,12 +4,26 @@ while getopts ":fhtvw-:" opt; do case "$opt" in -) case "${OPTARG}" in - foreground|help|test|version|wait) + wait) + WAIT=1 + ;; + help|version) + REDIRECT_STDERR=1 EXPECT_OUTPUT=1 - ;; + ;; + foreground|test) + EXPECT_OUTPUT=1 + ;; esac ;; - f|h|t|v|w) + w) + WAIT=1 + ;; + h|v) + REDIRECT_STDERR=1 + EXPECT_OUTPUT=1 + ;; + f|t) EXPECT_OUTPUT=1 ;; esac @@ -17,9 +31,19 @@ done directory=$(dirname "$0") +WINPS=`ps | grep -i $$` +PID=`echo $WINPS | cut -d' ' -f 4` + if [ $EXPECT_OUTPUT ]; then export ELECTRON_ENABLE_LOGGING=1 - "$directory/../../atom.exe" "$@" + "$directory/../../atom.exe" --executed-from="$(pwd)" --pid=$PID "$@" else "$directory/../app/apm/bin/node.exe" "$directory/atom.js" "$@" fi + +# If the wait flag is set, don't exit this process until Atom tells it to. +if [ $WAIT ]; then + while true; do + sleep 1 + done +fi diff --git a/src/browser/squirrel-update.coffee b/src/browser/squirrel-update.coffee index 0e4743a21..3660158fc 100644 --- a/src/browser/squirrel-update.coffee +++ b/src/browser/squirrel-update.coffee @@ -139,7 +139,7 @@ addCommandsToPath = (callback) -> atomShCommandPath = path.join(binFolder, 'atom') relativeAtomShPath = path.relative(binFolder, path.join(appFolder, 'resources', 'cli', 'atom.sh')) - atomShCommand = "#!/bin/sh\r\n\"$(dirname \"$0\")/#{relativeAtomShPath.replace(/\\/g, '/')}\" \"$@\"" + atomShCommand = "#!/bin/sh\r\n\"$(dirname \"$0\")/#{relativeAtomShPath.replace(/\\/g, '/')}\" \"$@\"\r\necho" apmCommandPath = path.join(binFolder, 'apm.cmd') relativeApmPath = path.relative(binFolder, path.join(process.resourcesPath, 'app', 'apm', 'bin', 'apm.cmd'))