Passing params to a java jar via exec.Command

653 views
Skip to first unread message

Mario Mueller

unread,
Apr 18, 2012, 4:48:50 AM4/18/12
to golan...@googlegroups.com
I'm working on a tool, which invokes some java binaries like: exec.Command(JAVABINARY, "-jar", YUIPATH, "-o", ".js$:.js", assetPath)
If I print the command, copy and run it, everything works fine, but if go's Command executes it, the jar complains about not finding the assetPath (FileNotFound Exception).

`ls` on the path works fine ..

anybody here who can help?

Brad Fitzpatrick

unread,
Apr 18, 2012, 9:19:28 AM4/18/12
to Mario Mueller, golan...@googlegroups.com
Do you need things in your environment that you don't have or are overriding? JAVA_HOME, etc.

What is assetPath?

Jan Mercl

unread,
Apr 18, 2012, 9:21:45 AM4/18/12
to golan...@googlegroups.com
I would probably give strace a try to verify how the args really look. Also, are the various paths handed over absolute? If not, are they correct relative to the wd?

Mario Mueller

unread,
Apr 18, 2012, 9:24:46 AM4/18/12
to golan...@googlegroups.com
All paths are absolute, the JAVA_HOME is not needed, as we pass the full qualified path to the java binary.



Here is dump of the command and the result of running ".CombinedOutput()" on the command. If I copy the command and run in on the shell, everything works fine.

2012/04/18 10:33:15 &{/usr/bin/java [/usr/bin/java -jar /home/mmueller/Development/Checkouts/project/php/legacy/admin/scripts/yui-compressor.jar -o .js$:.js /home/mmueller/Development/Checkouts/project/php/legacy/javascript/_statics/fi/*.js] []  <nil> java.io.FileNotFoundException: /home/mmueller/Development/Checkouts/project/php/legacy/javascript/_statics/fi/*.js (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at com.yahoo.platform.yui.compressor.YUICompressor.main(YUICompressor.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.yahoo.platform.yui.compressor.Bootstrap.main(Bootstrap.java:21)
 java.io.FileNotFoundException: /home/mmueller/Development/Checkouts/project/php/legacy/javascript/_statics/fi/*.js (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at com.yahoo.platform.yui.compressor.YUICompressor.main(YUICompressor.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.yahoo.platform.yui.compressor.Bootstrap.main(Bootstrap.java:21)

Jan Mercl

unread,
Apr 18, 2012, 9:40:53 AM4/18/12
to golan...@googlegroups.com
On Wednesday, April 18, 2012 3:24:46 PM UTC+2, Mario Mueller wrote:
All paths are absolute, the JAVA_HOME is not needed, as we pass the full qualified path to the java binary.



Here is dump of the command and the result of running ".CombinedOutput()" on the command. If I copy the command and run in on the shell, everything works fine.

2012/04/18 10:33:15 &{/usr/bin/java [/usr/bin/java -jar /home/mmueller/Development/Checkouts/project/php/legacy/admin/scripts/yui-compressor.jar -o .js$:.js /home/mmueller/Development/Checkouts/project/php/legacy/javascript/_statics/fi/*.js] []  <nil> java.io.FileNotFoundException: /home/mmueller/Development/Checkouts/project/php/legacy/javascript/_statics/fi/*.js (No such file or directory)

I think the '*' is your a problem. When invoked from a shell, it gets expanded. That doesn't happen with Cmd. Perhaps wrapping the whole command into sh -c is the way to go. Or collect the globbed file set in Go code in before and pass them instead of the * pattern.

Mario Mueller

unread,
Apr 18, 2012, 10:58:48 AM4/18/12
to Jan Mercl, golan...@googlegroups.com
Good point! I'll try that. Thanks!
Reply all
Reply to author
Forward
0 new messages