Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Grabbing tokens

by cbro (Pilgrim)
on May 13, 2003 at 14:12 UTC ( [id://257748]=note: print w/replies, xml ) Need Help??


in reply to Grabbing tokens

I ran a test and verified that this will work:
#!/usr/local/bin/perl $prg = "testers.sh"; $ret_var = <`$prg`>; print "\n\n$ret_var\n\n";
I got what testers.sh echoed back in $ret_val. As well, I verified that the command that testers.sh executed (`/bin/cp file1 file2`) worked too. So, the execution was not hindered, and the output of testers.sh was brought back into my Perl program for parsing. This should do it.
HTH,
Chris

Replies are listed 'Best First'.
Re: Re: Grabbing tokens
by Skeeve (Parson) on May 14, 2003 at 08:58 UTC
    Are you sure? I tried and it failed. To my understanding
    $ret_var = <`$prg`>;
    would first run $prg because of the backticks, and then try to handle this output as a filehandle.
    $ret_var = `$prg`;
    will do what you stated.
      Yes, I'm sure...otherwise, I would not have stated that I tested it.
      Here are the exact programs so that you can verify. I will admit, I did mistype one thing...I forgot to put the './' in the $prg scalar:
      ###Begin Perl### #!/usr/local/bin/perl $prg = "./testers.sh"; $ret_val = <`$prg`>; print "\n\n$ret_val:From Perl Not BASH Script\n\n"; ###End Perl#### ###Begin Bash### #!/usr/local/bin/bash `/bin/cp /wantstats.sh /newstats.sh` echo Success ###End Bash###
      What is printed:


      Success:From Perl Not BASH Script


      Try these scripts Skeeve. I wouldn't just claimed to have tested something...
        Not here!
        $ ./p1 `./testers.sh`:From Perl Not BASH Script $
        I think you don't know what thos `` mean! In your testers.sh I see:
        `/bin/cp /wantstats.sh /newstats.sh`
        Luckily /bin/cp doesn't have any STDOUTput! Just go ahead and enter:
        `echo ls`
        You will get the output of ls not the text "ls"!

        this is because `xxx` first execute xxx and then execute the output of xxx!

        No don't execute but try to imagine what this will do:
        `echo rm -rf \*`

Log In?
Username:
Password:

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

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

    No recent polls found