I compile an NSIS script to a .exe install file. I launch the .exe with command line \S silent option.
Installation performs silently as wanted, but there is exit code 1. Exit code 1 corresponds to case with user choosing cancel on the wizard. However, install is successful and mode is silent (no user interaction). Also, where does this exit code comes from, and how to manually enforce an exit code 0?
I have an idea i could do something in .onInstSuccess function, to enforce an exit code 1 if installation is successful.
Also, ExecWait is capturing the exit code into a variable, but has got no 'set' option.
What would you recommend?
Thanks and regards
Without any sample code it is a bit hard to guess what the problem could be!
You can set a specific exit code with SetErrorLevel.
As far as ExecWait goes, setting anything makes no sense, when it returns the child process has ended. If you want to use the exit code of a child process all you need is to get it:
ExecWait '"c:\foo.exe"' $0
SetErrorLevel $0
Related
When I start a new bash shell, if I run the command echo $? as the first thing, I get 1. How can I run bash with the "default" exit code being 0?
Context: I am running msys2 in a terminal window in VS Code. If I start msys2, and then realize I didn't need a shell now and just type exit, bash exits with 1, causing VS Code to pop up an annoying warning.
Most likely something in your profile is failing and setting the status code to 1. Since status codes are overwritten by each process that runs, it'll probably be something towards the end.
How do I negate the exit code of an executable in powershell? I would like my script to succeed if an executable terminated with a non-zero exit code, or fail if the executable terminated with a zero exit code.
I tried the following ! (...) and it prints True, which sounds promising, however it also makes the script fail with exit code 1.
! (program.exe) # I want this line to fail if program.exe returns 0
Output:
True
Error: Process completed with exit code 1.
Note that I'm just interested in checking the exit code of the executable. If the executable fails for other reasons (e.g. missing libraries) then it's fine for the script to fail.
This question has some similarities to this question for -nix systems. However, I'm writing a powershell script to be run on Windows 10.
I use TeamCity to que and report my TestComplete UI tests.
When the exit code in TestComplete is greater than 0 - it marks the build as a failure.
Exit codes for reference: https://support.smartbear.com/testexecute/docs/running/automating/command-line/exit-codes.html
Ideally I want an exit code of 1 to be marked as a warning in TeamCity - alternatively I would be happy to mark it as successful when it's an exit code 1. If it's any other exit code I'm happy to leave it as an unsuccessful "Build"
You can create a small command-line utility (or CMD/PowerShell script) that will run TestComplete using the parameters passed to the application itself and return exit codes as you want. Use this utility to run your tests instead of running TestComplete directly.
I'm writing some code in ruby, and I want to test for the presence of a command before the launch of the program. If the command isn't installed, I want to display an error message and quit the program. So right now, I'm doing this.
puts `type -P spark &>/dev/null && continue || { echo "You must install spark"; exit 0; } `
So, everything works fine, BUT, the "exit 0" isn't, and I can't figure out why.
Do you have any idea to fix this? Or even better, is there another way to do it?
The reason you're not exiting your script is that the call to exit is within the backticks. It's exiting the subshell called to run spark, but that's not the process interpreting your ruby script.
You could check the contents of the $? variable, which returns Process:Status for the backtick command after the command has been run.
As Daniel Pittman has suggested, however, it would be easier to check that the executable was available using something like FileTest. However, you probably want to couple that with a test of the return value, in case some other, more complex, failure occurs.
The much better way to do that is:
ENV["PATH"].split(':').any? {|x| FileTest.executable? "#{x}/spark" }
Season to taste for getting the full path, or using File.join to build the path, or platform path separators, or whatever.
For example I can directly call myscript.cmd or in other script I can put a line to myscript.
The reason is that if a script is run on it's own it dissapears as soon as it stop executing, so I can't see the result, so at the end I must add #pause but when I run it from another shell this causes annoyance since console window wouldn't exit that way.
So I look for some kind of 'if' condition to address this issue.
To get your script paused when double-clicked (or by dropping files on it), but terminating the usual way when invoked from console:
#echo off
echo Hello World!
:: ...your ScriptCode...
(((echo.%CMDCMDLINE%)|find /I "%~0")>NUL)&&pause
Unless you create an environment variable like Stu suggested, you're not going to find any that do what you want. You're going to need to write a small program that queries the parent process programmatically and returns a value your script can check. If you're being run from Start->run your parent will be explorer.exe. Otherwise it will be cmd.exe or some other exe.
Sample code to find the parent process can be found here.
Why not set it yourself?
SET RUNNINGFROMOTHERSHELL=YES
CALL MYSCRIPT.CMD
SET RUNNINGFROMOTHERSHELL=
In MyScript.Cmd:
IF "%RUNNINGFROMOTHERSHELL%"=="" GOTO NOPAUSE
PAUSE
:NOPAUSE