c# - Executed piped commands via System.Diagnostics.Process on Mono -
is possible execute following piped commands via system.diagnostics.process
?
echo "test" | sudo -s shutdown -r +1
i've tried setting file name "/bin/bash", above arguments, no success.
... var processstartinfo = new processstartinfo { filename = "/bin/bash", arguments = "echo \"test\" | sudo -s shutdown -r +1" }; process.startinfo = processstartinfo; ...
bash
interpreting command file name followed arguments, meaning invokes echo
, passes rest (including pipe |
) printing test | sudo -s shutdown -r +1
echoed , sudo
won't executed.
you should use -c
option execute command. furthermore, should quote command gets passed single argument. should work:
var processstartinfo = new processstartinfo { filename = "/bin/bash", arguments = "-c \"echo test | sudo -s shutdown -r +1\"" };
Comments
Post a Comment