result of system call

Discussion in 'C++' started by budgie, Oct 9, 2003.

  1. budgie

    budgie Guest

    Hi there,

    I'm using the system() function to call a program but would like to
    get the result of this operation.

    system returns an int depending on weather the command was executed
    successfully of not.

    How can I get a string -- or array of strings with the output of the
    camming line application instead?

    Thanks

    Karl
    budgie, Oct 9, 2003
    #1
    1. Advertising

  2. "budgie" <> wrote in message
    news:...
    > [...]
    > How can I get a string -- or array of strings with the output of
    > the camming line application instead?


    You would need to redirect the output of the application.
    On many systems, there is a fork() function, or something
    similar. In this way, your program can call another process
    and control several features, such as the I/O.

    Dave



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003
    David B. Held, Oct 9, 2003
    #2
    1. Advertising

  3. budgie

    Moonlit Guest

    Hi,

    Use
    popen( "command", "r" );

    then read from the returned descriptor. This method is one way either you
    read or write, but it is less code than fork.

    Regards, Ron AF Greve.



    "budgie" <> wrote in message
    news:...
    > Hi there,
    >
    > I'm using the system() function to call a program but would like to
    > get the result of this operation.
    >
    > system returns an int depending on weather the command was executed
    > successfully of not.
    >
    > How can I get a string -- or array of strings with the output of the
    > camming line application instead?
    >
    > Thanks
    >
    > Karl
    Moonlit, Oct 9, 2003
    #3
  4. budgie

    WW Guest

    Moonlit wrote:
    > Hi,
    >
    > Use
    > popen( "command", "r" );
    >
    > then read from the returned descriptor. This method is one way either
    > you read or write, but it is less code than fork.


    Neither popen, nor fork is a standard C or C++ function. They are POSIX
    functions, off-topic here. But that is not the point: since they aren't C
    and C++ functions it is nice to mention that fact once you post them into a
    C++ newsgroup.

    --
    WW aka Attila
    WW, Oct 9, 2003
    #4
  5. budgie

    klaas Guest

    budgie wrote:
    > Hi there,
    >
    > I'm using the system() function to call a program but would like to
    > get the result of this operation.
    >
    > system returns an int depending on weather the command was executed
    > successfully of not.
    >
    > How can I get a string -- or array of strings with the output of the
    > camming line application instead?
    >
    > Thanks
    >
    > Karl

    maybe
    char * d << system("yukk.exe");
    might work
    but then it probably will not
    but you could make it work with:
    my_string x << system("yukk.exe");
    but probably not, because standard out is standard out
    klaas, Oct 9, 2003
    #5
  6. budgie

    Ron Natalie Guest

    "klaas" <> wrote in message news:UKihb.11381$732.1216351@zonnet-reader-1...

    > maybe
    > char * d << system("yukk.exe");
    > might work
    > but then it probably will not
    > but you could make it work with:
    > my_string x << system("yukk.exe");
    > but probably not, because standard out is standard out


    System doesn't return strings. System returns a single int.
    If the argument is other than a null pointer, the value of this
    single int is implementation-defined.

    It's not a bunch of strings reflecting the output of the command
    invoked in any case.

    You will have to do this in a system dependent fashion. If you
    are on a UNIX/POSIX system, try popen.
    Ron Natalie, Oct 9, 2003
    #6
    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. J.Ram
    Replies:
    7
    Views:
    637
  2. Pavel
    Replies:
    7
    Views:
    503
    Pavel
    Sep 19, 2010
  3. Lakshmi Sreekanth

    i = 10; result = ++i - --i; How result become ZERO

    Lakshmi Sreekanth, Sep 21, 2010, in forum: C Programming
    Replies:
    52
    Views:
    1,132
    Nick Keighley
    Sep 23, 2010
  4. Mr. Buffoon
    Replies:
    4
    Views:
    277
    Eric Sosman
    Sep 23, 2010
  5. Michael Tan
    Replies:
    32
    Views:
    911
    Ara.T.Howard
    Jul 21, 2005
Loading...

Share This Page