Re: Redirecting STDOUT to a variable...
$datacapture = `$command`; $successorfailure = $?; - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, November 28, 2001 4:57 PM Subject: RE: Redirecting STDOUT to a variable... Hi Thanks, but I need to preserve the value returned by $mycommand also. I guess using backticks won't allow me to do that . Mostly what I need to do is read from STDOUT into a variable. But I don't know how to do that. Mayank -Original Message- From: Brett W. McCoy [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 28, 2001 11:56 AM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: Redirecting STDOUT to a variable... On Wed, 28 Nov 2001 [EMAIL PROTECTED] wrote: I am looking to run a command using perl and get its return value as well as its STDOUT. Currently I am doing is $result = system($myCommand out.txt); open(FILE, out.txt); and then processing the data from the file. This is terribly slow for my application. Is there some way where I can redirect the output directly to a variable and not have to do the file thing. Certainly. Use the backtick operator to slurp all of the output at once, use a scalar to store it all in one string, or put it into list context and dump each line into an array. my $result = `$myCommand`; my @result = `$myCommand`; If you think the output is going to be big, or you want to process each line of output as it occurs, you can do this: open CMD, $myCommand | or die couldn't fork: $!\n; while(CMD) { do something if /some pattern to match/; } close CMD; -- Brett http://www.chapelperilous.net/ The finest eloquence is that which gets things done. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Redirecting STDOUT to a variable...
On Wed, 28 Nov 2001 [EMAIL PROTECTED] wrote: I am looking to run a command using perl and get its return value as well as its STDOUT. Currently I am doing is $result = system($myCommand out.txt); open(FILE, out.txt); and then processing the data from the file. This is terribly slow for my application. Is there some way where I can redirect the output directly to a variable and not have to do the file thing. Certainly. Use the backtick operator to slurp all of the output at once, use a scalar to store it all in one string, or put it into list context and dump each line into an array. my $result = `$myCommand`; my @result = `$myCommand`; If you think the output is going to be big, or you want to process each line of output as it occurs, you can do this: open CMD, $myCommand | or die couldn't fork: $!\n; while(CMD) { do something if /some pattern to match/; } close CMD; -- Brett http://www.chapelperilous.net/ The finest eloquence is that which gets things done. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Redirecting STDOUT to a variable...
Hi Thanks, but I need to preserve the value returned by $mycommand also. I guess using backticks won't allow me to do that . Mostly what I need to do is read from STDOUT into a variable. But I don't know how to do that. Mayank -Original Message- From: Brett W. McCoy [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 28, 2001 11:56 AM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: Redirecting STDOUT to a variable... On Wed, 28 Nov 2001 [EMAIL PROTECTED] wrote: I am looking to run a command using perl and get its return value as well as its STDOUT. Currently I am doing is $result = system($myCommand out.txt); open(FILE, out.txt); and then processing the data from the file. This is terribly slow for my application. Is there some way where I can redirect the output directly to a variable and not have to do the file thing. Certainly. Use the backtick operator to slurp all of the output at once, use a scalar to store it all in one string, or put it into list context and dump each line into an array. my $result = `$myCommand`; my @result = `$myCommand`; If you think the output is going to be big, or you want to process each line of output as it occurs, you can do this: open CMD, $myCommand | or die couldn't fork: $!\n; while(CMD) { do something if /some pattern to match/; } close CMD; -- Brett http://www.chapelperilous.net/ The finest eloquence is that which gets things done. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Redirecting STDOUT
Hi all, I have a Perl script that takes the contents of a form, feeds them to GnuPG for encryption and then emails me the encrypted document. GPG wants to either display the results in STDOUT or write a text file, both of which arent good. I was hoping redirect STDOUT to a variable for a short time. Ive seen references to redirecting filehandles in the documentation, but no details on how to do it. (Which Im sure are there, but Ive just missed). Could someone point me where to look? Thanks, --Mark. __ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Redirecting STDOUT
Have you taken a look at the GnuPG or Crypt::GPG modules on CPAN? Yep, I've looked (and longed), but my Web hosting service refers to them as hooky. I think he's hostile because they aren't version 1 or higher (not that it really makes much difference). I also don't have the ability to directly ftp info into my cgi-bin, so I can't install the modules myself. I have to feed scripts to the hosting's support staff. I know using a module would be much better (I am quite the newbie), but I'm think I'm stuck trying it myself. So, other than changing hosting providers, any hints? --Mark. I have a Perl script that takes the contents of a form, feeds them to GnuPG for encryption and then emails me the encrypted document. GPG wants to either display the results in STDOUT or write a text file, both of which arent good. I was hoping redirect STDOUT to a variable for a short time. Ive seen references to redirecting filehandles in the documentation, but no details on how to do it. (Which Im sure are there, but Ive just missed). Could someone point me where to look? Thanks, --Mark. __ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Redirecting STDOUT
--- Mark Ross [EMAIL PROTECTED] wrote: Have you taken a look at the GnuPG or Crypt::GPG modules on CPAN? Yep, I've looked (and longed), but my Web hosting service refers to them as hooky. I think he's hostile because they aren't version 1 or higher (not that it really makes much difference). I also don't have the ability to directly ftp info into my cgi-bin, so I can't install the modules myself. I have to feed scripts to the hosting's support staff. I know using a module would be much better (I am quite the newbie), but I'm think I'm stuck trying it myself. So, other than changing hosting providers, any hints? --Mark. Well, here's one hint, though it may be a stretch: on a post at Perlmonks, someone claimed that they could not use CGI.pm due to the server [he] will be using [his program] on. Randal Schwartz pointed out that this still wasn't an excuse: http://www.perlmonks.org/index.pl?node_id=77669lastnode_id=9073 The point of that post is that there *are* ways you can sneak modules into your code. Give it a shot and see what happens. If your code is subjected to code review by the support staff, I can virtually guarantee that they do not know Perl terribly well. You may want to alter some of the comments and POD to disguise the source (if this is allowed under the license). Cheers, Curtis Poe = Senior Programmer Onsite! Technology (http://www.onsitetech.com/) Ovid on http://www.perlmonks.org/ __ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]