Download

Online

Gallery

Blog

  Index  | Recent Threads  | List Attachments  | Search
 Welcome Guest  |  Register  |  Login
Login Name  Password
 

Sweet Home 3D Forum



No member browsing this thread
Thread Status: Active
Total posts in this thread: 6
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 5839 times and has 5 replies Next Thread
treehousenorris2
Newbie



United States
Joined: Sep 14, 2020
Post Count: 15
Status: Offline
Reply to this Post  Reply with Quote 
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.

Thanks!
[Sep 14, 2020, 9:15:40 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9141
Status: Offline
Reply to this Post  Reply with Quote 
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
[Sep 15, 2020, 5:08:04 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
treehousenorris2
Newbie



United States
Joined: Sep 14, 2020
Post Count: 15
Status: Offline
Reply to this Post  Reply with Quote 
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);
}
}
[Sep 15, 2020, 6:42:24 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
treehousenorris2
Newbie



United States
Joined: Sep 14, 2020
Post Count: 15
Status: Offline
Reply to this Post  Reply with Quote 
Re: Spawn Shell Process

Got a shell to work from a plugin used with the SourceForge Sweet Home on Windows.


runProcess("cmd /c echo hello world", true);
// or
// String cmdFilePath = runProcess("where cmd", true);
// String cmdToRun = cmdFilePath +" /c echo hello world";

private String runProcess(String command, boolean shouldWait) {
try {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command);
if (!shouldWait) {
return null;
}

System.out.println("--"+command);
InputStream stdout = proc.getInputStream();
InputStreamReader isrout = new InputStreamReader(stdout);
BufferedReader brout = new BufferedReader(isrout);
String output = "";
String lineout = null;
System.out.println("<OUT>");
while ( (lineout = brout.readLine()) != null) {
output += (output.length() == 0 ? "" : "\n") + lineout;
System.out.println(lineout);
}
System.out.println("</OUT>");

InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
System.out.println("<ERROR>");
while ( (line = br.readLine()) != null) {
System.out.println(line);
}
System.out.println("</ERROR>");

int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
return output;

} catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
} catch (InterruptedException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
return null;
}

[Feb 5, 2021, 8:43:56 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
treehousenorris2
Newbie



United States
Joined: Sep 14, 2020
Post Count: 15
Status: Offline
Reply to this Post  Reply with Quote 
Re: Spawn Shell Process

Aha, the jre bundled with Sweet Home for Mac needed an executable permission on jspawnhelper.

chmod u+x /Applications/Sweet\ Home\ 3D.app/Contents/Plugins/Java.runtime/Contents/Home/jre/lib/jspawnhelper

or

<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"/>

[Mar 9, 2021, 3:26:26 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9141
Status: Offline
Reply to this Post  Reply with Quote 
Re: Spawn Shell Process

Thanks for the information about jspawnhelper, I updated build.xml accordingly.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D developer
[Mar 9, 2021, 4:10:34 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread

    Get Sweet Home 3D at SourceForge.net. Fast, secure and Free Open Source software downloads
   
© Copyright 2006-2024 eTeks - All rights reserved