Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Question on system function

by kprasanna_79 (Hermit)
on May 07, 2008 at 20:10 UTC ( [id://685317]=perlquestion: print w/replies, xml ) Need Help??

kprasanna_79 has asked for the wisdom of the Perl Monks concerning the following question:

Revered Monks,
I am running a binary file using system command and below is how i run it
sub { $file=shift; system "abc -add $file"; ($? != 0) ? return 0 : return 1; }
Its not showing me the input paramete option, where in binary i have asked to get a input from the user. I believe that is routed to different screen or trash. See below when i run the binary...
File contains 1 new key(s). Add these keyring ? (Y/n) Y
This particular line was not shown when i run through the perl script.
even i tried with qx and backtic. That didnt work.... Please any suggestion....
-Prasanna.K

Replies are listed 'Best First'.
Re: Question on system function
by apl (Monsignor) on May 07, 2008 at 20:33 UTC
    If I understand your question correctly, and assuming you're using *nix, you should probably change
    system "abc -add $file";

    to

    system "abc -add $file >abc.out 2>abc.err";

    You should see the messages in one file or the other.

Re: Question on system function
by carol (Beadle) on May 07, 2008 at 21:04 UTC

    If your abc program is perl also, use <STDIN> explicitly; not <>. In what follows echo.pl is your abc. kprasanna.pl is the script calling it.

    echo.pl:

    use strict; use warnings; my $arg = $ARGV[0]; my $line = <STDIN>; # bare <> won't work print "argument was $arg\ninputline was $line";

    kprasanna.pl:

    use strict; use warnings; my $file = $ARGV[0]; system "./echo.pl $file";

    Running it:

    duper:~/pp carol$ ./kprasanna.pl a_filename hello kprasanna # typed in at terminal argument was a_filename inputline was hello kprasanna duper:~/pp carol$

    Hope it helps.
Re: Question on system function
by pileofrogs (Priest) on May 07, 2008 at 20:24 UTC

    Are you running your script from the command line or from a cron job or something like that? If you don't have a tty, abc can know that and behave differently. You can fool it into thinking you have a tty when you don't, but I'm not sure off the top of my head how you do that. Expect probably has that capability.

    Soooo, I recommend you check out Expect.

    It looks like you're automating gpg. There might be gpg helper modules on CPAN as well.

    --Pileofrogs

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://685317]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 02:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found