print exit code in cmd in windows os [duplicate] - windows

This question already has answers here:
How do I get the application exit code from a Windows command line?
(7 answers)
Closed 9 years ago.
print exit code in cmd in windows os ....some command return exit code ...where this code store...and i want to print this exit code and assign it to variable

You can use %ERRORLEVEL% environment variable, it will hold the last code that was returned. You can echo it or assign it to a variable, depending on your needs.

Related

Echo path not working on my Windows 11 instance [duplicate]

This question already has answers here:
Display all environment variables from a running PowerShell script
(10 answers)
How to print environment variables to the console in PowerShell?
(5 answers)
Closed 4 months ago.
When entering echo path on PowerShell on my Windows 11, nothing proper is showing up.
I recall Windows 10 shows all environmental path variables, but not anymore?
ECHO %PATH% returns the value of the PATH environment variable when run in cmd.exe, but not PowerShell.
The PowerShell command you're looking for is as follows:
$env:PATH
If you need to list all environment variables in PowerShell, use gci env:. The equivalent command for cmd.exe is SET.
Please see this Stack Overflow post for more information.
Thanks to #mklement0 for the clarification.

How to pass a C program as a Command Line Argument [duplicate]

This question already has an answer here:
How to pass output as command line argument in bash? [duplicate]
(1 answer)
Closed 9 months ago.
The community reviewed whether to reopen this question 9 months ago and left it closed:
Original close reason(s) were not resolved
Im not sure if it is possible, but would like to know if i can use the result of a main() function as the command line argument for another program. im currently using gcc compiler on linux so i figure it would look something like this:
./listcommandlinearugments ./generaterandomstring
but this does not work... in the above example the first program (listcommandlinearguments) simply lists ./generaterandomstring as a command line arugment instead of using the result of the main funtion (0) because it was int main() and returned 0.
You can use backticks to insert the output of a program into another command:
./generaterandomstring `./listcommandlinearugments`
EDIT:
Since you want the return value of the listcommandlinearugments, run that first, then use $? to get the return value:
./generaterandomstring
./listcommandlinearugments $?

What is the windows command line equivalent to what role "$" plays in a Linux terminal? [duplicate]

This question already has answers here:
Batch equivalent of Bash backticks
(5 answers)
How to set commands output as a variable in a batch file [duplicate]
(9 answers)
Closed 3 years ago.
As the question title states, I want to know what control character is used in the windows command line when we want all content within the proceeding brackets to be evaluated as the output one expects if that content were executed on a separate command line for example in Linux to assign a value to a variable:
variable=$(a valid command sequence);

How to print bash command output and save to file? [duplicate]

This question already has answers here:
How to store the output of a command in a variable at the same time as printing the output?
(4 answers)
Capture stdout to a variable but still display it in the console
(5 answers)
Closed 3 years ago.
I am writing bash script and inside I am executing a command. I want to save the output of the command to variable but also want to print the output of the command to the standard output. I dont want to print the variable once the command is completed. How can I achieve this ?
Try the following, it will print the output of your command and assign to variable.
VAR="$(your_command| tee /dev/tty)"

Call a function in bash script with & [duplicate]

This question already has answers here:
What does "program &" mean on the command line?
(2 answers)
Closed 5 years ago.
Recently I am learning how to write bash script.
I noticed that in other's code, there is a line calling a function like this:
restartApp ${array[app]} $num &
I know the first two are variables that passing to the function, but I really don't understand what is the last symbol & here?
If you end the line with & the process starts in the background. This means you can continue to use the shell and do not have to wait on the output.

Resources