0

I need help on this part of a project I am making, I need to run a shell command and pass a variable either string or char to it.

p.runShellCommand("madplay /mnt/sda1/");

Above is my shell command which works, however I want to put a variable after the last slash

p.runShellCommand("madplay /mnt/sda1/variable");

The above code is what I have tried, replacing variable with my variable and didn't seem to work.

I have also tried this which seems to work

String hey = "madplay /mnt/sda1/worldOfTomorrow.mp3";
p.runShellCommand(hey);
demongolem
  • 9,474
  • 36
  • 90
  • 105
Vijay Yadav
  • 91
  • 13

1 Answers1

0

It's just string concatenation:

String command= "madplay /mnt/sda1/";
String var = "worldOfTomorrow.mp3";
p.runShellCommand(command+var);

Now, write in var with desired function:

String command= "madplay /mnt/sda1/";
String var = getNameOfFile();
p.runShellCommand(command+var);
...
public String getNameOfFile(){
//code retrieving your desired variable by Serial/SDcard/Ethernet....
}
jabujavi
  • 477
  • 5
  • 15