[Solved] Process begin syntax? Requires #!/bin/ash in scripts

Hi all :slight_smile:

I’ve upgraded to 1.5.0, and the process syntax below stopped working:

Process p;
p.begin("/path/to/shell_script.sh");
p.run();

Though, this syntax works:

Process p;
p.runShellCommand("/path/to/shell_script.sh");

Is this expected?

Here is a debug script I made:

#include <Bridge.h>
#include <Console.h>
#include <Process.h>

void setup() {
  Bridge.begin();
  Console.begin();
}

void loop() {
  Process p;
  p.runShellCommand("/root/ok.sh");
  //p.begin("/root/ok.sh");
  //p.run();
  int i = 0;
  char response[256];
  response[0] = '\0'; // empty as default
  Console.print("Response size: ");
  Console.println(p.available());
  while (p.available() > 0 && i < 256) {
    response[i] = p.read();
    i++;
    response[i] = '\0';
  }
  Console.print("Response: '");
  Console.print(response);
  Console.println("'");
  Console.print("Exit code: ");
  Console.println(p.exitValue());
  delay(1000);
}

Using p.begin and p.run gives:

Response size: 0
Response: ''
Exit code: 0

Using p.runShellCommand gives:

Response size: 7
Response: 'jej
OK
'
Exit code: 1

From console/ssh:

root@Arduino:~# cat ok.sh 
echo "jej"
/root/ok.py
exit 1
root@Arduino:~# cat ok.py 
#!/usr/bin/env python
print("OK")
root@Arduino:~# ls -l ok.*
-rwxr-xr-x    1 root     root            34 Oct  9 14:39 ok.py
-rwxr-xr-x    1 root     root            30 Oct  9 15:15 ok.sh
root@Arduino:~# ./ok.sh 
jej
OK
root@Arduino:~# echo $?
1

Peeking inside Process.cpp one helped me find the difference between runShellCommand and begin:

unsigned int Process::runShellCommand(const String &command) {
  runShellCommandAsynchronously(command);
  while (running())
    delay(100);
  return exitValue();
}

void Process::runShellCommandAsynchronously(const String &command) {
  begin("/bin/ash");
  addParameter("-c");
  addParameter(command);
  runAsynchronously();
}

In other words, one can do:

Process p;
p.begin("/bin/ash");
p.addParameter("-c");
p.addParameter("/path/to/script.sh");
p.addParameter("param1");
p.run();

But the real error was in ok.sh, adding #!/bin/ash helps. When logged in, ash already runs.

root@Arduino:~# cat ok.sh
#!/bin/ash
echo "OK"

Indeed an executable script requires the starting "hashbang". Can we consider this solved then? If so, can you change the title of the topic?