Skip to content

Instantly share code, notes, and snippets.

@jmewes

jmewes/notes.pl Secret

Created May 26, 2018 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmewes/15bfa58b0cb2aa9b490687fe0e0e522e to your computer and use it in GitHub Desktop.
Save jmewes/15bfa58b0cb2aa9b490687fe0e0e522e to your computer and use it in GitHub Desktop.
[Perl] How to execute system commands?
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