[Webinar] Streamline your web hosting managementRegister Today


perl, c program returns a negative value

Posted on 2012-09-12
Medium Priority
Last Modified: 2012-09-28
I have a perl program that calls a c program.  When I print $return_val, I don't get the same number that the my_c_program returned.  my_c_program returns negative and positive number.

my $return_val = '/tmp/my_c_program';
Question by:rgbcof
LVL 85

Expert Comment

ID: 38393703
my $return_val = '/tmp/my_c_program';
does not call a c program, it assigns a literal string to $return_val

If you had
my $return_val = `/tmp/my_c_program`;
then $return_val would contain whatever was printed to STDOUT by the execution of /tmp/my_c_program
LVL 13

Accepted Solution

Carl Bohman earned 1500 total points
ID: 38405971
If you are looking for the actual return code, you need to use the special $? variable.
my $StandardOutput =`/path/to/your/command with options`;
my $ReturnCode = $? >> 8;

Open in new window

Note that you need to bit-shift the return code as I did to get the "normal" return code that you might get via a shell script (for example).  The extra bits are flags that include information such as whether a core file was generated or not.  In most cases, you don't need those bits if you just want to see whether the command returned zero or not.

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question