very simple question:execute unix command inside script

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

Question by:tian
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Author Comment

ID: 1207814
Edited text of question

Accepted Solution

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;
LVL 84

Expert Comment

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.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Strange perl issue 6 137
unable to remove invisible characters with perl 2 99
Perl DBI Transactions Using Custom Module 7 49
html form to write data to csv 24 219
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.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

734 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