I like to portable-ise as many programs / apps as I can, so I regularly create self-executing SFX archives that extract to %temp% and then run a selected file (usually the original .exe or, if necessary, a .bat file).
I'm trying to combine a x86 and x64 version of an app into one version, as I don't like having 2 files. So, I have 2 folders ("x86" and "x64") containing the different versions of the program and a .bat file in the root that will check the user's bitness and then launch the appropriate version. I'm having a few issues, though.
Here is my code:
checkandrun.bat
#echo off
goto Payload
:Payload
echo Checking architecture bit-type...
IF EXIST "%systemRoot%\SysWOW64" (
echo Your version of Windows is 64-bit [x64]
start "x64\GCFScape.exe" >nul
) ELSE (
echo Your version of Windows is 32-bit [x86]
start "x86\GCFScape.exe" >nul
)
echo.
echo Starting the appropriate version...
goto End
:End
echo.
echo This window will close in 20 seconds.
ping localhost -n 21 >nul
exit
If I use start then the original command window will exit correctly, as desired, but will open up a new, constant command window and the app won't launch.
If I don't use start the app will launch but the command window will stay open and won't progress past the line of code that was used to launch the .exe. If I close the app itself then the command window will proceed as normal to the exit command and close successfully.
Is there is a way around this? I've never had this kind of problem before.
Here is a link to the SFX archive in my Dropbox, if anyone wants to take an actual look at the environment and effects for themselves: https://dl.dropbox.com/u/27573003/Social%20Distribution/gcfscape182.exe
The docs for the START command say that the first arg that is in quote marks will be the title of the window. So, try this:
start /B "GCFScape" "x64\GCFScape.exe">nul
Related
I want to run octave-gui (Octave 5.1 installed with installer and "C:\Octave\mingw64\bin" is in path variable) scripts run by Windows Task Scheduler. I have to run octave-gui since I want to use the qt toolkit for plotting that octave (without gui) does not support. Therefore I normally use simple bat files like "octave-gui --no-gui c:\path\myfile.m".
But the problem is that I cannot run this bat file by clicking in the Windows Explorer or running from command line. Even the most simple bat file with the content "octave-gui --no-gui" gives me the following error:
But the funny part is that I can make it work somehow:
open command line
run "octave" or "octave-gui" and close/quit it
then I can the bat file from the command line
But this could not be the solution, could it? This only works in the (interactive) command line. How does it work in the Task Scheduler?
So, do you have a solution to run either batch files using octave-gui or octave with qt toolkit.
Here is the workaround with "where" as asked by Gerhard:
The command octave is technically incorrect.
It works only from your Command Prompt window because its extension .bat is listed within the values assigned to an unmodified environment variable %PATHEXT%. It also assumes that there are no other files named octave.com or octave.exe, anywhere within the any of the directories listed under your environment variable %PATH%. Additionally it also assumes that there is not an executable file named octave with any extension listed under %PATHEXT% in the current directory when invoked.
You should, for safety, use octave.bat instead.
octave.bat
Octave.bat will parse any input arguments, set up the required environment, and then run either start octave-gui.exe --gui %* or octave-cli.exe %* if it detected --no-gui as one of the input arguments.
Additionally when running a batch file from another, (in this case start_my_octave_script.bat), you should Call it if you're wanting control to return to it afterwards, which will almost certainly be the case.
call octave.bat <command line options>
If you're satisfied that your %PATHEXT% environment variable is unmodified or at least holds the default values, you can omit the .batextension, but please bear in mind the previous advice.
call octave <command line options>
I made a workaround thanks to the hints made by Compo. It seems to me that a solution must be done in the "octave.bat" and so I did. I made a copy and named it "octave-gui-nogui-withqt.bat" and removed all the gui checking stuff and only run "octave-gui.exe --no-gui" (scroll down):
:; # if running from bash, recall using cmd.exe
:; cmd.exe //c "$0" "$#"; exit $?
#echo off
Rem Find Octave's install directory through cmd.exe variables.
Rem This batch file should reside in Octaves installation bin dir!
Rem
Rem This trick finds the location where the batch file resides.
Rem Note: the result ends with a backslash.
set OCT_HOME=%~dp0\.\..\
Rem Convert to 8.3 format so we don't have to worry about spaces.
for %%I in ("%OCT_HOME%") do set OCT_HOME=%%~sI
Rem Set up PATH. Make sure the octave bin dir comes first.
set PATH=%OCT_HOME%qt5\bin;%OCT_HOME%bin;%PATH%
Rem Set up any environment vars we may need.
set TERM=cygwin
set GNUTERM=wxt
set GS=gs.exe
Rem QT_PLUGIN_PATH must be set to avoid segfault (bug #53419).
IF EXIST "%OCT_HOME%\qt5\bin\" (
set QT_PLUGIN_PATH=%OCT_HOME%\qt5\plugins
) ELSE (
set QT_PLUGIN_PATH=%OCT_HOME%\plugins
)
Rem set home if not already set
if "%HOME%"=="" set HOME=%USERPROFILE%
if "%HOME%"=="" set HOME=%HOMEDRIVE%%HOMEPATH%
Rem set HOME to 8.3 format
for %%I in ("%HOME%") do set HOME=%%~sI
Rem Start Octave (this detaches and immediately returns).
Rem make this call in order to have qt on the cli
octave-gui.exe --no-gui %*
Is this the most elegant one? I guess that upstream Octave should allow a new option like "--no-gui-but-use-qt" or similar. What do you think?
It still confuses me that "octave-cli.exe" and "octave-gui.exe" have more differences besides the visible gui.
I am on windows 10 and i need to run multiple executable files from a batch file silently, without waiting for them to finish. at the moment i have:
#echo off
start "" "%~dp0executable.exe" /q
start "" "%~dp0executable2.exe" /q
but this still opens multiple console windows.
any workarounds that achieve the same results are welcome.
Your executables seem to be console applications, otherwise no console window would appear.
Anyway, the start command features an option /B; here is an excerpt of the output of start /?:
B Start application without creating a new window. The
application has ^C handling ignored. Unless the application
enables ^C processing, ^Break is the only way to interrupt
the application.
By ^C and ^Break, pressing Ctrl + C and Ctrl + Pause/Break is meant, respectively.
In case you have a third .exe that needs to wait after the first two started simultaneously you can also use the start /w argument for the second one and call the third like so:
#echo off
start /B "%~dp0executable.exe"
start /W "%~dp0executable2.exe"
call "%~dp0executable3.exe"
I'm trying to run Flyway migrations on 11 different databases at the same time. I'm doing this via a batch file...
#echo off
setlocal
set FLYWAY_EXE=C:\flyway-3.2.1\flyway
for /d %%f in (%~dp0props_flyway\*) do (
start "%%~nf" %FLYWAY_EXE% migrate -configFile=%~dp0props_flyway\%%~nf\flyway.conf
)
set FLYWAY_EXE=
#echo on
This approach works fine, but it leaves me with 11 command prompt windows open and I need to manually go into each and type "exit". Is it possible for these command prompt windows to automatically close after the flyway migration has done its work to save me having to close them all manually?
I can do it without using start. It then performs the migrations consecutively, however I'd rather do them in parallel to save time.
I have tried the approach of using an empty string after start from this question, but this does nothing for me on Windows 8.1, except to open the command prompt with an empty title instead of the one I want to have.
I've also tried...
cmd /c "start ^"%%~nf^" %FLYWAY_EXE% migrate -configFile=%~dp0props_flyway\%%~nf\flyway.conf"
...to no avail.
Anyone know how I can start each of these migrations up and have them close automatically upon completion?
You just want to exit the command window?
You have to escape the ampersands
Just change your command by tacking on " && exit" to end
TRY:
start "%%~nf" %FLYWAY_EXE% migrate -configFile=%~dp0props_flyway\%%~nf\flyway.conf ^&^& exit
I'm trying to create a script to copy a secure exe file to the C directory from a flash drive that is assigned the drive letter D. Then to run the exe, delete the exe, then shut down the PC. I have technicians who need to do this in order to make a biometric reader function properly. They keep screwing up the process and I would like to automate the process to save me a headache. The file is secure and cannot be leaked to our customers due to licensing. I already tried a batch script, but the exe doesn't seem to launch correctly.
Here's what I had:
COPY "D:\Biometric\software.exe" "C:\software.exe"
Pause
pushd C:\
Start "C:\software.exe"
Pause
pushd C:\
erase "software.exe" /F /Q
Pause
c:\windows\system32\shutdown -s -f -t 00
I've never tried VBScript, and I figured maybe that might get me the results I need, any help would be appreciated.
Start considers the first set of quotes it finds to be the window's title, so what you have in your code essentially says "set the window's title to 'C:\software.exe' and then execute the start command on nothing."
Insert an extra set of quotes to make the start command work.
start "" "C:\software.exe"
I'm testing an application in a stress test.
That's why I need it to restart if an error occurs (an error window opens) or it hangs or crashes. At the same time I need to collect all the useful information about the problem which lead to a restart: make a dump file and copy the error text from the error window (and/or take its screenshot).
With bash it's easy: Restarting program automatically on crash in OSX (without screenshots or dumps, but the error window stays on MacOS, so they are practically not needed there). However, I need this functionality to run on Win (XP/Vista/7).
I can use special monitoring tools for restart, but that way I would rely on non-standard programs. I can use User Mode Process Dumper on XP, but it doesn't work for Vista.
Is there any elegant and universal way (batch file or perl script would be great) to implement described functionality for all versions of Windows?
Regarding the 1st part of your question, you can test if a process is running using tasklist.
This will run myapp.exe, restarting it if necessary:
#echo off
set MYAPP=myapp.exe
rem # Loop infinitely and restart the application if it's not running
:Start
tasklist /FI "IMAGENAME eq %MYAPP%" 2>NUL | find /I /N "%MYAPP%" >NUL
if errorlevel 1 %MYAPP%
call :Sleep 1
goto Start
rem # A short sleep subroutine to yield system resources
:Sleep
ping 127.0.0.1 -n %1 -w 1000 > nul
Regarding the 2nd part of your question, you can collect a user mode core dump using AutoDumpPlus.
For instance:
adplus -crash -quiet -pn myapp.exe -o C:\temp
This will run ADPlus, monitoring all processes named myapp.exe, and producing a core dump in the output directory C:\temp (of course, this can be changed) if a crash is detected.
I haven't tested this setup as a whole, but I hope it works for you!