How to retrieve the Perl script returned value in C program? Many thanks

Discussion in 'Perl Misc' started by mike, Apr 24, 2007.

  1. mike

    mike Guest

    Hi Guys:

    I have an Email application that was made of C(no source code). Only I
    know is that it can call a program with a parameter(email file name)
    and check the return value. If returns 0, go ahead and work with the
    next one; return 1, drop it, and work with next one.

    I intend to use Perl script to check the email's FROM field. Once it
    comes from a specific domain, then return 1; otherwise, return 0.

    Here comes the question: How can I return 0 or 1 from Perl script to
    the C program? I made a C test program, and called the Perl script
    this way:

    int ret_val = system("perl_script email_file_name");

    When I call exit(0) in the Perl script, the ret_val in the C test
    program is 0; but when I call exit(1) in the Perl script, the ret_val
    in the C test program is 256,

    How come it happens this way? Any suggestion would be appreciated.

    Mike
    mike, Apr 24, 2007
    #1
    1. Advertising

  2. mike

    Mumia W. Guest

    Re: How to retrieve the Perl script returned value in C program?Many thanks

    On 04/24/2007 02:39 PM, mike wrote:
    > [...]
    > When I call exit(0) in the Perl script, the ret_val in the C test
    > program is 0; but when I call exit(1) in the Perl script, the ret_val
    > in the C test program is 256,
    >
    > How come it happens this way? Any suggestion would be appreciated.
    >
    > Mike
    >


    Shift the return value right by eight bits.
    Mumia W., Apr 25, 2007
    #2
    1. Advertising

  3. mike <> wrote:

    > Subject: How to retrieve the Perl script returned value in C program? Many thank



    The same way you would retrieve an exit value (not a return value)
    from a program written in any other programming language.

    That is, you have a C question, not a Perl question.

    comp.lang.c is over thataway ==>

    :)


    > Here comes the question: How can I return 0 or 1 from Perl script to
    > the C program?



    That is not the same question as in your Subject...

    perldoc -f exit


    > I made a C test program, and called the Perl script
    > this way:
    >
    > int ret_val = system("perl_script email_file_name");
    >
    > When I call exit(0) in the Perl script,



    It looks like you already know how to exit with a 0 or 1 from
    your Perl program.


    > the ret_val in the C test
    > program is 0; but when I call exit(1) in the Perl script, the ret_val
    > in the C test program is 256,
    >
    > How come it happens this way? Any suggestion would be appreciated.



    I would suggest reading the documentation for the (C) system() function.

    (it very likely behaves similarly to Perl's system() function,
    so maybe you could get a clue from reading that description...)


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Apr 25, 2007
    #3
  4. mike

    mike Guest

    Thanks a lot for all you guys suggestion.
    mike, May 1, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,784
  2. Annie
    Replies:
    0
    Views:
    344
    Annie
    Nov 22, 2006
  3. Niels Dekker - no reply address

    The best way to retrieve a returned value... by const reference?

    Niels Dekker - no reply address, May 27, 2009, in forum: C++
    Replies:
    19
    Views:
    711
    James Kanze
    Jun 4, 2009
  4. David Graham

    many thanks

    David Graham, Nov 27, 2003, in forum: Javascript
    Replies:
    1
    Views:
    62
    David Graham
    Nov 27, 2003
  5. mike
    Replies:
    2
    Views:
    90
Loading...

Share This Page