Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Problems Returning Different Values to Shell Script using Perl Script

by EchoAngel (Pilgrim)
on Nov 09, 2004 at 23:39 UTC ( [id://406562]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks I have this example. Within a shell script, asdf.sh, I do `setenv script.pl`; Inside the script.pl, it will print out a menu and list options for users to enter and etc. I want to return back to the shell script the variable and data so I can set up the tools. IE setenv PEOPLE 321-23. But since i'm outputing to screen a menu, that text will get into setenv. Any help?
  • Comment on Problems Returning Different Values to Shell Script using Perl Script

Replies are listed 'Best First'.
Re: Problems Returning Different Values to Shell Script using Perl Script
by tachyon (Chancellor) on Nov 10, 2004 at 00:20 UTC

    Why not just do it all in Perl?

    #!/usr/bin/perl $ENV{PEOPLE} = '321-23'; # setenv PEOPLE $res = menu(); # some menu function that gets input # call shell stuff via `cmd` qx[ cmd ] system('cmd') exec('cmd') # backtics get you STDOUT results, add 2>&1 to capture STDERR as well my $results = `cmd $some $args 2>&1`; print "Got $results\n"; # system lets you check exit codes but ingnores output system("cmd"); my $exit_val = $? >> 8; # exec mutates the perl script into some other program exec("there_can_be_only_me");

    cheers

    tachyon

Re: Problems Returning Different Values to Shell Script using Perl Script
by saintmike (Vicar) on Nov 10, 2004 at 00:02 UTC
    Just print the menu to STDERR and the result to STDOUT. Similar to this shell bookmark script.
Re: Problems Returning Different Values to Shell Script using Perl Script
by perlcapt (Pilgrim) on Nov 10, 2004 at 02:55 UTC
    In a shell script, you can substitute any result into any aspect of the script by enclosing the routine in backquotes. For example:
    $ export IE=`myScript.pl $someShellValue $etc`
    I'm not much of a csh user, but I believe it would be something like this:
    % setenv IE `myScript.pl $someShellValue $etc`
    I really don't understand your last statement:
    But since i'm outputing to screen a menu, that text will get into setenv.
    . Would you restate it with different words, please.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2024-04-18 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found