Newbie question - execute jar file in ruby
-
@niccah said:
Oh thank you very much. Now, I just get an error like this: "Error: #<Errno::ENOEXEC: Exec format error - Model2GCode.jar",
try:
output =
java Model2GCode.jar #{ARGSTRING}`` -
That's almost it... but it needs a
-jar
flag to execute the .jar file...
UseDir.chdir()
to the jar file's folder folder then use
output =
java -jar Model2GCode.jar #{ARGSTRING}``
[Works for me...] -
FYI the switches for java.exe (probably also javaw.exe)
Usage; java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file) where options include; -client to select the "client" VM -server to select the "server" VM -hotspot is a synonym for the "client" VM [deprecated] The default VM is client. -cp <class search path of directories and zip/jar files> -classpath <class search path of directories and zip/jar files> A ; separated list of directories, JAR archives, and ZIP archives to search for class files. -D<name>=<value> set a system property -verbose[;class|gc|jni] enable verbose output -version print product version and exit -version;<value> require the specified version to run -showversion print product version and continue -jre-restrict-search | -jre-no-restrict-search include/exclude user private JREs in the version search -? -help print this help message -X print help on non-standard options -ea[;<packagename>...|;<classname>] -enableassertions[;<packagename>...|;<classname>] enable assertions -da[;<packagename>...|;<classname>] -disableassertions[;<packagename>...|;<classname>] disable assertions -esa | -enablesystemassertions enable system assertions -dsa | -disablesystemassertions disable system assertions -agentlib;<libname>[=<options>] load native agent library <libname>, e.g. -agentlib;hprof see also, -agentlib;jdwp=help and -agentlib;hprof=help -agentpath;<pathname>[=<options>] load native agent library by full pathname -javaagent;<jarpath>[=<options>] load Java programming language agent, see java.lang.instrument -splash;<imagepath> show splash screen with specified image
-
You are the best!
With the help of your tips I could solve the "Exec format error"! Thanks your very very much!
The next problem:
I wrote two very easy jar files:
1th version: just: System.out.println("Hello world!"); => but with the following code, I get a false.
output = nil output = `java -jar Model2GCode.jar #{ARGSTRING}` result=$?.success?
2nd version: Thread.sleep(10000); => I get a false too.
When I start the jar file outside of sketchup, everything is fine.
Do you have an idea, what can I do? I'm not sure, if it is an problem of Sketchup, Ruby or Java...
Thanks you for all your help!
-
$?
isnil
when Sketchup first starts.
After a subprocess runs it may be set to a integer value, for the exit status.The method name
success?
is not an instance method of eitherNilClass
norInteger
(nor it's subclasses, such asFixnum
.)You should test the
output
reference (since you first set it tonil
, which Ruby will eval asfalse
in a conditional statement.)output = nil output = `java -jar Model2GCode.jar #{ARGSTRING}` if not output if $? != nil || $? != 0 puts("The error code returned was; #{$?.to_s}") else puts("No error code was returned.") end else # do something with the output string end
You cannot call
Thread.sleep()
as it is a private instance method of theThread
class (and raises aNoMethodError
exception.)Use the global method
sleep()
(which is inherited from moduleKernel
,) instead.
Warning.. usingsleep()
can cause "whiteout" (Windows can put the SketchUp application into "ghost-window mode".) -
Thanks Dan Rathbun!!
By using your method - I get an empty output.
output = nil output = `java -jar Model2GCode.jar #{ARGSTRING}` if not output if $? != nil || $? != 0 puts("The error code returned was; #{$?.to_s}") else puts("No error code was returned.") end else UI.messagebox output end
I see the UI.messagebox, but it is empty.
My Java code is just aSystem.out.println("Hello world!");
As I read in some forums, the "output" of the java application should be the "System.out.println"'s. So, I'm confused, why it doesn't work?!
-
Yes I tried it also, and got no output.
I tried in in a command shell and got java errors.Sorry I cannot help you with java.
Why use java when SketchUp uses Ruby ??
-
Java won't print to the Ruby/SUp messagebox how does it know it.
Use an Alert in the Java code...
http://www.java2s.com/Code/JavaAPI/javax.microedition.lcdui/Alert.htm -
@dan rathbun said:
Yes I tried it also, and got no output.
I tried in in a command shell and got java errors.Sorry I cannot help you with java.
Why use java when SketchUp uses Ruby ??
I'm coding a plugin for Sketchup to get a GCode for a CNC milling maschine for a 3D Model. So, multithreading would be very nice to accelerate the calculating. The ruby version of Sketchup doesn't support something like that. So I try to use an external Java application for the main calculations.
-
Hmmm... OK. Yes, actually it's Ruby 1.8.x itself that uses "green threads" instead of native threads.
You might have more luck using a OLE interface to the java.
See: [Plugin Library] Win32API and Win32OLE so files
and: WIN32OLE rdoc
Advertisement