-
-
Save jmewes/15bfa58b0cb2aa9b490687fe0e0e522e to your computer and use it in GitHub Desktop.
[Perl] How to execute system commands?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
sub cmd { | |
my ($command) = @_; | |
eval { | |
my $result = system(1, qq^bash -i -c '$command'^); | |
print "result: $result\n"; | |
} | |
} | |
#system('bash -i -c "less /tmp/test.txt"); | |
#system('echo \'test\''); # (/) | |
#system(q|echo "test"|); # (/) | |
#system(q|bash -i -c 'less /tmp/test.txt'|); # (/) | |
#system(q|bash -i -c 'less "/tmp/test.txt"'|); # (/) | |
#system(q|bash -i -c 'less '/tmp/test.txt''|); # (/) | |
#system(q^bash -i -c 'less '/tmp/test.txt''^); # (/) | |
#cmd("sudo apt-get update && sudo apt-get upgrade"); | |
unless (kill 0 => $kid_pid) { | |
warn "something wicked happened to $kid_pid"; | |
} | |
system("kill 1 0"); | |
print "line 1"; | |
print "line 2"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment