nanophd has asked for the wisdom of the Perl Monks concerning the following question:
Wise PerlMonks, I consider myself a novice at perl and I am in need of some assistance. I have an issue with regards to executing an alias from Perl. I have a script that that keeps track of my inputs in a file. When'-c' is inputed it should ask for a command, write the command to the file, execute command and write the output to the file as well. Then it should return back to the loop.
`$cmd` was working fine for build in commands, but would not execute alias commands. I read that I would need to use the command
`bash -c -i "$cmd"` This fixed the kinda fixed the problem, except it would exit the program and not reenter the loop.Is there any way to run an alias command and continue with the rest of the code?
Here is the section of my code that is at fault:Thank you in advance.if($input eq "-c"){ print "Enter Command: "; my $cmd = <STDIN>; print $fh $cmd; print $fh "\n\t#### START COMMAND OUTPUT ####\n"; print `bash -c -i "$cmd"`; foreach(`bash -c -i "$cmd"`){ print $fh "#".$_; } print $fh "\t#### END COMMAND OUTPUT ####\n"; next; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to execute alias commands
by choroba (Cardinal) on Jan 13, 2014 at 23:31 UTC | |
|
Re: How to execute alias commands (source your profile)
by Anonymous Monk on Jan 13, 2014 at 23:13 UTC | |
by nanophd (Novice) on Jan 14, 2014 at 15:42 UTC | |
by nanophd (Novice) on Jan 14, 2014 at 17:15 UTC | |
|
Re: How to execute alias commands
by ww (Archbishop) on Jan 13, 2014 at 22:44 UTC | |
by nanophd (Novice) on Jan 14, 2014 at 15:32 UTC |