dacro
May 5, 2022, 11:03am
1
Hi,
I try to run this command
osascript -e 'do shell script "sudo installer -pkg /path/to/some.pkg -target /" with administrator privileges'
with
juce::String pkgFilePath = "/path/to/some.pkg";
juce::String command = "osascript -e 'do shell script \"sudo installer -pkg " + pkgFilePath + " -target /\" with administrator privileges'";
juce::ChildProcess *driverInstallerCommand = new juce::ChildProcess();
driverInstallerCommand->start(command);
juce::String driverInstallOutput = driverInstallerCommand->readAllProcessOutput();
// print output
but I get this error: 0:1: syntax error: A unknown token can’t go here. (-2740)
I tried a lot of escaping. I guess it is just some small adjustment to get this running.
In Terminal the command runs without any problems.
Any ideas?
Thanks,
David
reuk
May 5, 2022, 11:12am
2
There was a post the other day where the solution seemed to be to split the arguments up using a StringArray:
I’ve been trying to execute some command-line programs from JUCE with pipes such as ps aux | grep chrome and I want to launch it with juce::ChildProcess.
Somethin’ like:
juce::ChildProcess cp;
cp.start ("ps aux | grep chrome");
juce::String output = cp.readAllProcessOutput();
DBG ("Command Output:\n" + output + "\n");
uint32 exitCode = cp.getExitCode();
Problem is, the juce::ChildProcess does not seem to recognize the pipe character “|” as I am expecting. For the varying piped commands I…
Maybe something like this (untested)?
StringArray { "osascript", "-e", "do shell script \"sudo installer -pkg /path/to/some.pkg -target /\" with administrator privileges" };
1 Like
dacro
July 7, 2022, 10:12am
3
Thanks, I did not saw your answer until today. I will try it in the next days.
Did anyone verify if this works or not? I can’t get it to work in a mildly complicated situation. It took me several hours to figure out the correct combination of , ', and " to get this command to properly work on the command line.
String cmd = "osascript -e \"do shell script \\\"mv '" + source.getFullPathName() + "' " + destination.getParentDirectory().getFullPathName() + " \\\" with administrator privileges\"";
Console output of cmd results in:
osascript -e "do shell script \"mv '/Users/cr/Library/Caches/myApp/my.vst3' /Library/Audio/Plug-Ins/VST3 \" with administrator privileges"
If I paste this line in Terminal, it runs. But when I send it to ChildProcess, it results in the error:
**19:19: syntax error: Expected “"” but found end of script. (-2741)**
Which is super helpful. This smells like a similar issue to the other two threads on this subject, but with so many quotes and backslashes, trying to part this out in to a StringArray is proving… difficult.
Does anyone who has done this before have some insight?
The solution, for those searching for help on osascript in the future, is to use system() rather than ChildProcess().
e.g. make your String cmd above; make sure the output works by DBG(cmd) and copy-pasting it to a Terminal.
Then:
system(cmd.toRawUTF8());
1 Like