Hello,
one question about the Process-library: is there any difference between starting a Process p using
p.begin("cmd");
p.addParameters("par");
p.run();
and using
p.runShellCommand("cmd par");
?
Thx for help,
Martin
Hello,
one question about the Process-library: is there any difference between starting a Process p using
p.begin("cmd");
p.addParameters("par");
p.run();
and using
p.runShellCommand("cmd par");
?
Thx for help,
Martin
There are some subtle differences. The first method is more flexible and gives you greater control (including the ability to run the command asynchronously in the background while the sketch continues to run) while the second method involves less typing.
The biggest difference is that the first one will run the "cmd" directly, passing it "par" as a parameter, while the second one will run an instance of /bin/ash, passing it two parameters: "-c" to signal that it should run a command, and "cmd par" as the command to be run.
So if you are running an external process, like a Python script, the first method is a bit more efficient since it runs the script directly, while the second method runs a command interpreter, which then runs the script.
On the other hand, if you are trying to run a command that is part of /bin/ash itself (like a busybox command) then only the second version will work unless you use /bin/ash as the command in the begin() call.
Thank you for the fast and detailed answer!
So when executing a shell-script which itself starts with #!/bin/ash it would make more sense to start it with p.run()?