Solved

Take care of the output from system(...)

Posted on 1999-01-22
7
141 Views
Last Modified: 2010-03-05
Hi
How do I take care of the output from the systemfunction.
Ex.
system("useradd -g users -d /home/.......");
Lets say it doesnt work and says something here. If it were in ordinary shellscript you could redirect the output to a logfile (>>logfile), but if I want perl to print it to a logfile.

Thanks
Classe
0
Comment
Question by:cl071997
  • 3
  • 2
  • 2
7 Comments
 
LVL 4

Expert Comment

by:martinag
ID: 1210243
open(LOG, ">log.log") or die "can't open file: $!";
print LOG `useradd -g users -d /home/.......`; # Note the backticks!
close LOG;

Martin
0
 

Author Comment

by:cl071997
ID: 1210244
The example looks nice, but it doesn´t works. I tried it careully.
It do reports to STDOUT but doesn´t prints it to the LOG.

Try it, does it really work for you...I tried on both Linux and HP-UX.
Perl version 5.004_003.

Regards
Classe
0
 
LVL 4

Expert Comment

by:martinag
ID: 1210245
Works great.
What is printed to the logfile? Nothing?

Martin
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:cl071997
ID: 1210246
Thats right - nothing...but the message comes to the screen (STDERR).


Classe
0
 
LVL 84

Expert Comment

by:ozo
ID: 1210247
`useradd -g users -d /home/.......  2>&1`
0
 

Author Comment

by:cl071997
ID: 1210248
Offcourse...thanks alot !!!

Classe
0
 
LVL 84

Accepted Solution

by:
ozo earned 200 total points
ID: 1210249
see also
perldoc -q STDERR
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl script help 12 105
compress files in RAR using perl 13 84
what are these modules in perl script 4 103
Is it true to say that Python is successor of Perl? 7 190
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question