Java receives an error executing Ruby script; Terminal doesn't

流过昼夜 提交于 2019-12-11 04:58:36

问题


This is a forked problem off of this question: flac: "ERROR: input file has an ID3v2 tag" (it doesn't). I've solved the initial issue there but that didn't resolve one problem I was having, so I'm going to introduce it separately here.

I'm using a Ruby gem called speech2text to convert an audio file into (approximated) text. Calling it on the command line works fine (Mac Terminal). However, the following Java code:

String[] cmd = {"speech2text", "tmp/audio/pop-test-audio.wav"};

    ProcessBuilder builder = new ProcessBuilder(cmd);
    builder.redirectErrorStream(true);
    Process process = builder.start();

Only receives this back from the process streams:

/Library/Ruby/Gems/1.8/gems/speech2text-0.3.4/lib/speech/audio_inspector.rb:50:in `initialize': undefined method `first' for nil:NilClass (NoMethodError)
from /Library/Ruby/Gems/1.8/gems/speech2text-0.3.4/lib/speech/audio_splitter.rb:77:in `new'
from /Library/Ruby/Gems/1.8/gems/speech2text-0.3.4/lib/speech/audio_splitter.rb:77:in `initialize'
from /Library/Ruby/Gems/1.8/gems/speech2text-0.3.4/lib/speech/audio_to_text.rb:15:in `new'
from /Library/Ruby/Gems/1.8/gems/speech2text-0.3.4/lib/speech/audio_to_text.rb:15:in `to_text'
from /Library/Ruby/Gems/1.8/gems/speech2text-0.3.4/bin/speech2text:11
from /usr/bin/speech2text:19:in `load'
from /usr/bin/speech2text:19

I don't know anything about Ruby, hence my lightweight use of the library through Java. I really can't tell what's going on here, but I know that it works when executed in exactly the same way from the Terminal. Has anyone got any idea what might be causing this?


回答1:


You could also ditch the terminal and try JRuby. It's just as fast as the normal Ruby VM and is easier to integrate with Java.




回答2:


I have had similar issues trying to run jslint.js (for node.js). I actually did better running bash first, then print writing in my commands that way, but even that had problems as I recall.

Basically the problem is that executing things with Java can fail when environment settings that would otherwise be available are not loaded. This can be a tough one to solve.



来源:https://stackoverflow.com/questions/9861510/java-receives-an-error-executing-ruby-script-terminal-doesnt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!