I was wondering if there is a way to get Linux commands with a perl script. I am talking about commands such as cd ls ll clear cp
I was wondering if there is a way to get Linux commands with a
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can execute system commands in a variety of ways, some better than others.
system();, which prints the output of the command, but does not return the output to the Perl script.qx();function, which is easier to read and accomplishes the same thing.exec();, which does the same thing assystem();, but does not return to the Perl script at all, unless the command doesn’t exist or fails.open();, which allows you to either pipe input from your script to the command, or read the output of the command into your script.It’s important to mention that the system commands that you listed, like
cpandlsare much better done using built-in functions in Perl itself. Any system call is a slow process, so use native functions when the desired result is something simple, like copying a file.Some examples:
This page explains in a bit more detail the different ways that you can make system calls.