How can I call a shell command in my Perl script? -


can give me example on how can call shell command, 'ls -a' in perl script , way retrieve output of command well.

how run shell script perl program

1. using system system($command, @arguments);

for example:

system("sh", "script.sh", "--help" );

system("sh script.sh --help");

system execute $command @arguments , return script when finished. may check $! errors passed os external application. read documentation system nuances of how various invocations different.

2. using exec

this similar use of system, terminate script upon execution. again, read documentation exec more.

3. using backticks or qx//

my $output = `script.sh --option`;

my $output = qx/script.sh --option/;

the backtick operator , it's equivalent qx// excute command , options inside operator , return commands output stdout when finishes.

there ways run external applications through creative use of open, advanced use; read documentation more.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -