exit-code

Getting exit status code from 'ftp' command in linux shell

为君一笑 提交于 2019-11-30 04:11:56
I need to retrive the exit status code from a command line program. No worries, I used $?. But for ftp, even if it doesn't connect, it opens the ftp shell, so I'm not able to understand that the connection haven't take place. Try this code for understand: #!/bin/sh ftp 1234567 OUT=$? if [ $OUT -eq 0 ];then echo "ftp OK" else echo "ftp Error: "$OUT fi exit 0 Any help? Thanks Filippo You should be looking for success message from ftp command rather than looking for a status. It's "226 Transfer complete". You can confirm it with ftp manual on your system. 200 PORT command successful. 150 Opening

Bash conditional based on exit code of command

你说的曾经没有我的故事 提交于 2019-11-29 17:00:47
In Bash, I would like an if statement which is based of the exit code of running a command. For example: #!/bin/bash if [ ./success.sh ]; then echo "First: success!" else echo "First: failure!" fi if [ ./failure.sh ]; then echo "Second: success!" else echo "Second: failure!" fi success.sh #!/bin/bash exit 0 failure.sh #!/bin/bash exit 1 This should print out: First: success! Second: failure! How would I achieve this? Thanks! Just remove the brackets: #!/bin/bash if ./success.sh; then echo "First: success!" else echo "First: failure!" fi if ./failure.sh; then echo "Second: success!" else echo

exec Exit Code Meaning for 11

眉间皱痕 提交于 2019-11-29 15:31:19
I'm using the following code on a linux web server $error = exec('phantomjs table1.js', $op, $code); echo $code; // prints 11 on screen table1.js var page = require('webpage').create(); var url = 'table1.php'; page.open(url, function (status) { page.render('ss/table1.png'); phantom.exit(); }); table1.php echo '<h1>This should be converted to an image</h1>'; I went through this link but that code isn't listed there. Any idea what this exit code stands for? Code 11 is a "segmentation fault": A segmentation fault (also segfault) is caused by a program when it tries to allocate data in a piece of

Is it up to the programmer to deallocate on exit()?

走远了吗. 提交于 2019-11-29 15:12:27
I have a program and when I input wrong data from the keyboard it just exits with exit(1) . I was testing with Valgrind and while this happens there are no errors, but I can see that there are still reachable x bytes. So my question: Is it up to the programmer to free memory before hitting an exit() or is the OS going to take care of it? It's a good idea (and in old enough versions of Windows, it was essential), but when a program exit() s on modern operating systems its entire address space is reclaimed. In the end, the OS will take care of it (on every modern OS, it was not the case with

Why can't I return bigger values from main function?

柔情痞子 提交于 2019-11-29 11:12:28
问题 I am trying to return a bigger value like 1000 from my main function, but when I type echo $? it displays 0. If I return a smaller value like 100 it displays the correct value. My Code: int main(void) { return 1000; } Is there any limitation on the values which we can return? 回答1: There are two related concepts here: C exit status, and bash return code. They both cover the range 0-255, but bash uses numbers above 126 for it's own purposes, so it would be confusing to return those from your

seccomp — how to EXIT_SUCCESS?

寵の児 提交于 2019-11-29 09:08:50
Ηow to EXIT_SUCCESS after strict mode seccomp is set. Is it the correct practice, to call syscall(SYS_exit, EXIT_SUCCESS); at the end of main? #include <stdlib.h> #include <unistd.h> #include <sys/prctl.h> #include <linux/seccomp.h> #include <sys/syscall.h> int main(int argc, char **argv) { prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT); //return EXIT_SUCCESS; // does not work //_exit(EXIT_SUCCESS); // does not work // syscall(__NR_exit, EXIT_SUCCESS); // (EDIT) This works! Is this the ultimate answer and the right way to exit success from seccomp-ed programs? syscall(SYS_exit, EXIT_SUCCESS); //

Why is ErrorLevel set only after || operator upon a failed redirection?

烈酒焚心 提交于 2019-11-29 06:33:23
Upon a failed redirection (due to a non-existent file or insufficient file access), the ErrorLevel value seems not to be set (in the following examples, file test.tmp is write-protected and file test.nil does not exist): >>> (call ) & rem // (reset `ErrorLevel`) >>> > "test.tmp" echo Text Access is denied. >>> echo ErrorLevel=%ErrorLevel% ErrorLevel=0 >>> (call ) & rem // (reset `ErrorLevel`) >>> < "test.nil" set /P DUMMY="" The system cannot find the file specified. >>> echo ErrorLevel=%ErrorLevel% ErrorLevel=0 However, as soon as the failed redirection is followed by the conditional

Use of System.exit(0) [duplicate]

ぐ巨炮叔叔 提交于 2019-11-29 03:45:57
This question already has an answer here: Difference in System. exit(0) , System.exit(-1), System.exit(1 ) in Java 11 answers public class WrapperTest { static { print(10); } static void print(int x) { System.out.println(x); System.exit(0); } } In the above code System.exit(0) is used to stop the program. What argument does that method take? Why do we gave it as 0 . Can anyone explain the concept? From the JAVA Documentation : The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination. And Wikipedia adds additional information. It's the return

Setting exit code in Python when an exception is raised

本秂侑毒 提交于 2019-11-29 01:04:31
$ cat e.py raise Exception $ python e.py Traceback (most recent call last): File "e.py", line 1, in <module> raise Exception Exception $ echo $? 1 I would like to change this exit code from 1 to 3 while still dumping the full stack trace. What's the best way to do this? Take a look at the traceback module. You could do the following: import sys, traceback try: raise Exception() except: traceback.print_exc() sys.exit(3) This will write traceback to standard error and exit with code 3. 来源: https://stackoverflow.com/questions/6720119/setting-exit-code-in-python-when-an-exception-is-raised

How to get the exit status of a Java program in Windows batch file

允我心安 提交于 2019-11-28 22:50:34
Analogous to the $? in Linux, is there a way to get the exit status of a program in a Windows batch file ( .bat )? Say for example the program has a System.exit(0) upon successful execution, and a System.exit(1) upon a failure, how do I trap these exit values in a .bat file? Use %ERRORLEVEL% . Don't you love how batch files are clear and concise? :) Something like: java Foo set exitcode=%ERRORLEVEL% echo %exitcode% It's important to make this the absolute next line of the batch file, to avoid the error level being overwritten :) Note that if you use the IF ERRORLEVEL number "feature" of batch