System calls question

Discussion in 'Perl Misc' started by tweetiebirds@gmail.com, May 6, 2005.

  1. Guest

    When calling system I would like the standard output to be printed to
    standard out.

    This is not happening - how do I make it happen:


    system ("cp a b");


    T
    , May 6, 2005
    #1
    1. Advertising

  2. Damian James Guest

    On 5 May 2005 18:18:53 -0700, said:
    > When calling system I would like the standard output to be printed to
    > standard out.
    > This is not happening - how do I make it happen:
    > system ("cp a b");
    >


    print `cp a b`;

    perldoc -q "Why can't I get the output of a command with system()?"
    perldoc -f system

    and see the section on qx// in perldoc perlop

    Or if you need to take more control over the other process, see
    the pipe version of open (ie, where MODE is '-|')

    perldoc -f open


    Cheers,
    Damian
    --
    @:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
    $:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
    $,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
    Just another Perl Hacker,### http://home.pacific.net.au/~djames.hub
    Damian James, May 6, 2005
    #2
    1. Advertising

  3. jesper Guest

    wrote:

    > When calling system I would like the standard output to be printed to
    > standard out.
    >
    > This is not happening - how do I make it happen:
    >
    >
    > system ("cp a b");
    >
    >
    > T

    Well try

    $result = `cp a b`;
    printf $result;

    does only print after execution though.
    jesper, May 6, 2005
    #3
  4. <> wrote:

    > When calling system I would like the standard output to be printed to
    > standard out.



    Good, as that is the default behavior.


    > This is not happening



    Then there is a bug in your perl installation.


    > system ("cp a b");



    What output are you expecting from cp(1)?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, May 6, 2005
    #4
  5. Re: System calls question

    Damian James wrote:

    > On 5 May 2005 18:18:53 -0700, said:
    > > When calling system I would like the standard output to be printed
    > > to standard out.
    > > This is not happening - how do I make it happen:
    > > system ("cp a b");
    > >

    >
    > print `cp a b`;
    >
    > perldoc -q "Why can't I get the output of a command with system()?"
    > perldoc -f system
    >
    > and see the section on qx// in perldoc perlop
    >
    > Or if you need to take more control over the other process, see
    > the pipe version of open (ie, where MODE is '-|')
    >
    > perldoc -f open
    >


    That being said, you won't get any output on stdout with the above
    command, though you may get some on stderr.

    Mark
    Mark Clements, May 6, 2005
    #5
  6. Damian James Guest

    Re: System calls question

    On 06 May 2005 05:56:03 GMT, Mark Clements said:
    > Damian James wrote:
    >
    >> On 5 May 2005 18:18:53 -0700, said:
    >> > When calling system I would like the standard output to be printed
    >> > to standard out.
    >> > This is not happening - how do I make it happen:
    >> > system ("cp a b");
    >> >

    >> print `cp a b`;
    >>
    >> perldoc -q "Why can't I get the output of a command with system()?"
    >> perldoc -f system
    >>
    >> and see the section on qx// in perldoc perlop
    >>
    >> Or if you need to take more control over the other process, see
    >> the pipe version of open (ie, where MODE is '-|')
    >>
    >> perldoc -f open
    >>

    >
    > That being said, you won't get any output on stdout with the above
    > command, though you may get some on stderr.


    Indeed. And system() does indeed send the other program's STDOUT to STDOUT,
    so my suggestion above was pointless. Two things I just didn't spot, not
    really my day ;)

    --damian
    Damian James, May 6, 2005
    #6
  7. Joe Smith Guest

    jesper wrote:

    > $result = `cp a b`;
    > printf $result;


    Best to break the C habits.
    Don't use printf without a format.
    Use a plain print instead.
    Joe Smith, May 6, 2005
    #7
  8. Joe Smith Guest

    wrote:
    > When calling system I would like the standard output to be printed to
    > standard out.
    >
    > system ("cp a b");


    Change that to either
    system("cp -v a b");
    or
    system("cat a b");
    depending on what you're really trying to accomplish.
    -Joe
    Joe Smith, May 6, 2005
    #8
  9. Anno Siegel Guest

    jesper <> wrote in comp.lang.perl.misc:
    > wrote:
    >
    > > When calling system I would like the standard output to be printed to
    > > standard out.
    > >
    > > This is not happening - how do I make it happen:
    > >
    > >
    > > system ("cp a b");
    > >
    > >
    > > T

    > Well try
    >
    > $result = `cp a b`;
    > printf $result;


    Nonsense. That doesn't change the printing of stdout one whit.

    Anno
    Anno Siegel, May 6, 2005
    #9
    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. Honne Gowda A
    Replies:
    2
    Views:
    872
    Karl Heinz Buchegger
    Oct 31, 2003
  2. andy6
    Replies:
    2
    Views:
    756
    andy6 via DotNetMonster.com
    Jun 9, 2006
  3. markus
    Replies:
    22
    Views:
    659
    Dances With Crows
    Sep 22, 2004
  4. Richard Tobin
    Replies:
    24
    Views:
    784
  5. Bob
    Replies:
    5
    Views:
    259
Loading...

Share This Page