Solved

very simple question:execute unix command inside script

Posted on 1998-06-11
3
168 Views
Last Modified: 2010-03-05
Hello,
How can I execute unix commands like "ls" ,"date" inside perl script and print output to a file?

thanks
0
Comment
Question by:tian
3 Comments
 

Author Comment

by:tian
ID: 1207814
Edited text of question
0
 
LVL 4

Accepted Solution

by:
martinag earned 50 total points
ID: 1207815
# This puts the output from date function in $date.
# Be sure to use backticks!
$date = `date`;

# Print result to output.txt
open (OUTPUT, ">output.txt") or die "can not open file: $!";
print OUTPUT $date;
close OUTPUT;
0
 
LVL 84

Expert Comment

by:ozo
ID: 1207816
and if you're specifically interested in `ls` and `date`,
it would be faster and more portable to use the built in readdir and localtime functions.
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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…

749 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