To have a perl script return a certain error code to the system, do
in the perl script or the like.
But your perl script has bigger problems already, like the error message says. It may be returning unexpected errors due to the syntax problems in your script.
The system() function will exec a sh and return its exit status. The exit status of "perl_src.c_pl ${fl} || { echo \"$?, wrong;\"; }" will always be 0, unless the echo fails (which is very unlikely).
Something along the lines of the following is probably want you want:
Although, personally, I don't see the point of echoing from the shell pipeline (unless that was part of your troubleshooting process). You can check the exit status in the C code and generate the appropriate message there.
I think, I am not clear enough. Corona688 - I do not have a problem with the perl-script. The error is found and corrected.
I need to be sure that any perl-script problem (script could be changed) will be propagaited into C program and correctly ends the program!
alister - you are right, I am 'echo'ing the result to see that value now, when I debuging the situation.
The main intention is to 'exit $?' - expecting to have in C the same value as it was returned by the perl-script.
By now I exiting with hardwired '2' - as it returned currently by the perl (but it could be different!)
Anyway, by your ansvers, guys, I have realised one point: in the line
the '$?' is substituted by shell BEFORE starting the 't_sys' - because the 'double quotes'!
My mistake here!
But, alister -
- your point is correct and understood, but the problem is not in the overwriting the return code by echo, but in comming out after the system() - now I see that I had it passed in wrong way.
Anyway, in correct passing way it still comming through the system() changed:
??? Now it even more unclear: Still system() returns something weird: 1280 instead of 5; but the program some why exiting with 2!!!
What is wrong??
Anyway, in correct passing way it still comming through the system() changed:
??? Now it even more unclear: Still system() returns something weird: 1280 instead of 5; but the program some why exiting with 2!!!
What is wrong??
Thank you for your attention!
First, you need to read the man page on system(3). The return value is of the format returned by wait(2). Thus, you need to feed that into the WEXITSTATUS macro to get the actual return value.
Second, you are not returning a value from your main function. The 2 is just a value left over on the stack.
Here's a quick cut at correcting your program (I'm not at a Linux system at the moment so I can't check it):
I took care of handling the case where the child process gets a signal though the program exit status won't reflect it correctly.
You aren't declaring main() to return an int, although the compiler is probably taking care of this for you.
main() is not returning a value.
rt is not the simple integer exit status that you think it is. rt contains other information regarding how the process exited (for example, if by a signal, which sig). You need to read the waitpid() man page for the details (which include macros to extract the actual exit status from system's return value).
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)
Hello ,
I need to write a script that by using scp transfer a csv file from UNIX to a MFT system (MFT is similar to a winscp) with the help of a private/public key. problem is we are not suppose to generate a private key that will be provided to use by an Application team.
Can anybody help me... (0 Replies)
How to do I get the return code of a subroutine in a perl module if invoke the subroutine as standalone,
I have an module say TestExit.pm and in that i have a subroutine say myTest() which is returns 12, if i were to call the subroutine from
command line like
CASE:1 ( Without an explict... (2 Replies)
Dear Friends,
I need urgent help from u..
I have two files,file1 & file 2..
file1 have a existing data of file2.So i want to delete those existing datas from file1 (which contain the data from file1)
My file1 like this
rs39348 1 1045729 A G 0.1791 0.2054 0.84 ... (3 Replies)
When I run a bash script in the customer system, it throws the warning and script exits
Exec '/root/sample.sh' @ hostname-- OK
(warn) /root/sample.sh: pipe error: Too many open files in system
/root/sample.sh: n + : syntax error: operand expected (error token is " ")
Exec... (5 Replies)
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)
Hi,
It is very urgent.
Pls guide me in learning Perl Module and the Packages.
Eventhough i tried in the google, I didnt get upto my expectations.
Pls guide me how to create , build Module and the package.
Many Thanks. (3 Replies)
perl 5.6.1:
when i try a "system" command(with if loops for $?), i get this:
child exited with value 1
what is meant by this $? values and what does it meant if it returns 1?.. (0 Replies)