Return code from system()


 
Thread Tools Search this Thread
Top Forums Programming Return code from system()
# 1  
Old 01-08-2007
Error Return code from system()

Hi,

Can any one help me in knowing how can I get the return codes/Error codes when using the system() command to fork a command?

Regards,
MK
# 2  
Old 01-08-2007
system() returns a status for executed command in the format that can be decoded by macros in sys/wait.h - like WIFEXITED.

You need to read: man 2 wait
Most of the time you call these two:
Quote:
WIFEXITED(stat_val) Evaluates to a non-zero value if status
was returned for a child process that
terminated normally.

WEXITSTATUS(stat_val) If the value of WIFEXITED(stat_val) is
non-zero, this macro evaluates to the
low-order 8 bits of the status argument
that the child process passed to _exit()
or exit(), or the value the child
process returned from main().
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[solved] awk: return code from system() always 0 ??

Hi all, I currently have the following problem: In an awk script, I am calling a predifend function from the END{} and handing over a command string. This string arrives flawless and is executed like this: function send_msg( cmd_str ) { ... (7 Replies)
Discussion started by: zaxxon
7 Replies

2. Shell Programming and Scripting

How could I use the value of return code

Hello, I am woring on a script where I am getting strange situation.This script actually fetch the source code and tar that code and send to NAS location.This code resides in MKS tool...and we are fetching the source code on checkpoint label basis and script is working fine.First it synch the... (0 Replies)
Discussion started by: anuragpgtgerman
0 Replies

3. Shell Programming and Scripting

C, sh, perl, system(): Can't transfer a return code appropriately: help, pls

I am using a perl-script from C-code, executing it by the 'system(..)' comand. The problem is to return the perl-return code to the C correctly. Default the 'system()' shell is Bourne: sh My try: (perl_src.c_pl - the perl script; t_sys - C-program with system() call (I will show it... (7 Replies)
Discussion started by: alex_5161
7 Replies

4. Shell Programming and Scripting

return code help

Hello folks, I have a question that if i type ls command and type echo $? it always show "0", how i could do this change that when i type ls it will show me 1, actually i want to change the return code of commands from 0 to 1. Thanks Bash (5 Replies)
Discussion started by: learnbash
5 Replies

5. Shell Programming and Scripting

Need help with return code 1...

Hi Guys,, I am having a unix script which is running the DB2 Insert command. For the insert command, there were no records to be updated. SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. SQLSTATE=02000 + + echo 1 STAGE_RC=1 + ] ... (6 Replies)
Discussion started by: mac4rfree
6 Replies

6. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

7. Shell Programming and Scripting

asking about return code

hi all my system is linux red hat i have a script that runs some object . the object return some code to the system i see the code by writing echo $? i want to ask in the script if $? equals 14 how shell is do that in the script thanks (3 Replies)
Discussion started by: naamas03
3 Replies

8. Programming

How to get system() function executed cmd return value ?

Hi, How I can get system function executed command return value ? I want to know mv command success or not ? #include <stdio.h> main() { int ret; ret = system( "mv x.dat y.dat" ); printf( "system ret:\n", ret ); } (3 Replies)
Discussion started by: haiudhaya
3 Replies

9. UNIX for Advanced & Expert Users

Return code from PL/SQL Code

Hi Guys, I was just wondering if anybody can help me with this problem. OK, how we can get a value back from PL/SQL Script (not stored procedure/function) See the below example: (for example aaa.sh) #!/bin/ksh VALUE=`sqlplus -s user/password@test_id <<EOF @xxx.sq EOF` echo $VALUE ... (7 Replies)
Discussion started by: Shaz
7 Replies

10. Shell Programming and Scripting

return code from oracle

I am writing a unix script that logs into oracle and does a count on a table. I want to return that count to my unix script. this is my script: #!/bin/ksh typeset retcode; numin=0 sqlplus -s <<-EOSQL myuser/mypass@mydb variable ret_val number; begin ... (3 Replies)
Discussion started by: lesstjm
3 Replies
Login or Register to Ask a Question