Solved

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

Posted on 1999-01-22
7
139 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
Comment Utility
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
Comment Utility
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
Comment Utility
Works great.
What is printed to the logfile? Nothing?

Martin
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

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


Classe
0
 
LVL 84

Expert Comment

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

Author Comment

by:cl071997
Comment Utility
Offcourse...thanks alot !!!

Classe
0
 
LVL 84

Accepted Solution

by:
ozo earned 200 total points
Comment Utility
see also
perldoc -q STDERR
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
perl search and replace 6 161
Filtering a file to table 9 98
Perl Script - Remove row of data based on column value 3 72
Awk Question 2 116
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 …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now