ba6.us - Dave's Database Related Stuff

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

Tag Cloud

apex data development export funnies Hint HTML import linux monitoring oem oracle performance perl pl/sql reporting rman scripting solaris sql 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.
  • 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.
13 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.


Cornify
  • home
  • blog
  • notes
  • projects
  • recent
  • about
  • !

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