United States
Joined: Sep 14, 2020
Post Count: 15
Status:
Offline
Spawn Shell Process
Hello!
I'd like to execute a shell command from my plugin's java.
I am getting "cannot run program" errors, such as the following. Is there anything Sweet Home specific to folder or spawn permissions that would affect this?
`hdiutil mount ~/Downloads/SweetHome3D-6.4.2-macosx.dmg` `cd ‘/Volumes/SweetHome3D-6.4.2/Sweet Home 3D.app/Contents/MacOS’` `./SweetHome3D`
java.io.IOException: Cannot run program "sh" (in directory "/bin"): error=316, spawn failed at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
java.io.IOException: Cannot run program "adb" (in directory "/usr/local/bin"): error=316, spawn failed at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
I'm working on a plugin to act as a one-click exporter to transfer the home's .obj file (etc) from a mac onto an android mobile device.
France
Joined: Nov 7, 2005
Post Count: 9180
Status:
Offline
Re: Spawn Shell Process
What Java method did you try to run your command? Under which Sweet Home 3D version? I wouldn’t be astonished that the sandboxed version available on the Mac App Store doesn’t allow such a feature.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D developer
United States
Joined: Sep 14, 2020
Post Count: 15
Status:
Offline
Re: Spawn Shell Process
Sweet Home 6.4.2 from SourceForge. To see the Sweet Home stdout I am using the dmg>app>executable because I wasn't able to get the Sweet Home jar to run from the terminal (not on mojave but worked on a catalina machine). Mojave only works by double clicking the Sweet Home jar, which defaults to open with Jar Launcher, but without stdout.
@Override public void execute() { routine(); }
public void routine() { Process process; try { process = Runtime.getRuntime().exec( new String[]{"bash", "-c", "pwd"}, null, new File("/bin")); printResults(process); } catch (IOException e) { e.printStackTrace(); } }
public void printResults(Process process) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { System.out.println(line); } }
<target name="macosxBundle"... <!-- Change executable permission of jspawnhelper lost during copy task --> <chmod perm="+x" file="install/macosx/SweetHome3D-${version}/Sweet Home 3D.app/Contents/Plugins/Java.runtime/Contents/Home/jre/lib/jspawnhelper"/>
France
Joined: Nov 7, 2005
Post Count: 9180
Status:
Offline
Re: Spawn Shell Process
Thanks for the information about jspawnhelper, I updated build.xml accordingly.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D developer