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