ba6.us - Dave's Database Related Stuff

  • home
  • blog
  • notebooks
  • projects
  • recent
  • about
  • manifesto
  • !
Home › Blogs › dmann's blog

Tag Cloud

apex Application Express Auditing data dbi development export funnies HTML Java linux monitoring oem oracle performance perl rman scripting sql SQL Developer sqlplus tuning unix windows
more tags

Search

RSS Feed

Blog Posts :

Navigation

  • Feed aggregator

User login

  • Request new password

Getting return value and output text with Perl...

dmann — Wed, 09/05/2007 - 14:51

I know using Perl backticks call I can execute an OS command and easily get the output. I know using Perl system() call I can execute an OS command and easily get the return value. Today I found out a way to get both. This example is on Windows, but if you are on Unix, substitute 'ls' for 'dir'.
#!/bin/perl

# Execute dir command
$command = `dir`;

# Show the output of the command
#split by newlines, put into @alloutput array
@alloutput = split /\n/, $command;  

#loop once for each item in @alloutput array
foreach $outputline (@alloutput) {   
    print qq[Output: $outputline\n];
}

# Now show the return value
print "Return value: $?";
Voila! You can have your output and return value too! -- Dave
  • perl
  • dmann's blog

Post new comment

The content of this field is kept private and will not be shown publicly.
Input format
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
3 + 7 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.


Cornify
  • home
  • blog
  • notebooks
  • projects
  • recent
  • about
  • manifesto
  • !

Content Copyright 2006-2010. Links are copyright of respective owners.