Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Windows计算机上从Processing/Java运行SoX_Java_Windows_Cmd_Processing_Sox - Fatal编程技术网

在Windows计算机上从Processing/Java运行SoX

在Windows计算机上从Processing/Java运行SoX,java,windows,cmd,processing,sox,Java,Windows,Cmd,Processing,Sox,这可能是一个简单的问题,但现在我快发疯了。我正在尝试运行SoX从处理,在我的mac电脑上运行平稳,没有问题。我需要将代码迁移到windows 7计算机上,但由于某些原因无法使其工作。从加工厂到终端的通话很好。由于我可以运行“dir”等命令并打印出正确的内容,所以我在正确的文件夹中(SoX也在草图数据文件夹中),但只要我尝试运行SoX.exe,就什么也没有发生(获得退出值1)。直接从cmd终端运行sox.exe可以正常工作。以下是我尝试做的一个示例: void playBackYear (){

这可能是一个简单的问题,但现在我快发疯了。我正在尝试运行SoX从处理,在我的mac电脑上运行平稳,没有问题。我需要将代码迁移到windows 7计算机上,但由于某些原因无法使其工作。从加工厂到终端的通话很好。由于我可以运行“dir”等命令并打印出正确的内容,所以我在正确的文件夹中(SoX也在草图数据文件夹中),但只要我尝试运行SoX.exe,就什么也没有发生(获得退出值1)。直接从cmd终端运行sox.exe可以正常工作。以下是我尝试做的一个示例:

void playBackYear (){

soxPlay = "cmd /c sox.exe year.wav -d";
  println (soxPlay);
 try {
    File workingDir = new File(sketchPath("data"));
    Process p=Runtime.getRuntime().exec(soxPlay, null, workingDir);
    p.waitFor(); 
    BufferedReader reader=new BufferedReader(
    new InputStreamReader(p.getInputStream())
      ); 
    String line; 
    while ( (line = reader.readLine ()) != null) 
    { 
      println(line);
    }
   int exitVal = p.waitFor();
   System.out.println("Exited with error code "+exitVal);
  } 

  catch(IOException e1) {
   System.err.println("Caught IOException: " + e1.getMessage());
   System.out.println( "error 1" );
  } 
  catch(InterruptedException e2) {
   System.err.println("Caught IOException: " + e2.getMessage());
   System.out.println( "error 2" );
  } 

}
所以问题是我做错了什么?
非常感谢您的帮助。

我已经编写了一个小型包装应用程序,用java包装sox二进制文件。如果您对整个项目感兴趣,请在GitHub上查看:

这就是我解决问题的方法:

private List<String> arguments = new ArrayList<String>();
// add sox arguments to this list above

public void execute() throws IOException {
    File soxBinary = new File(soXBinaryPath);
    if (!soxBinary.exists()) {
        throw new FileNotFoundException("Sox binary is not available under the following path: " + soXBinaryPath);
    }

    arguments.add(0, soXBinaryPath);
    logger.debug("Sox arguments: {}", arguments);
    ProcessBuilder processBuilder = new ProcessBuilder(arguments);
    processBuilder.redirectErrorStream(true);
    Process process = null;
    IOException errorDuringExecution = null;
    try {
        process = processBuilder.start();
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            logger.debug(line);
        }
    } catch (IOException e) {
        errorDuringExecution = e;
        logger.error("Error while running Sox. {}", e.getMessage());
    } finally {
        arguments.clear();
        if (process != null) {
            process.destroy();
        }
        if (errorDuringExecution != null) {
            throw errorDuringExecution;
        }
    }
}
private List arguments=new ArrayList();
//将sox参数添加到上面的列表中
public void execute()引发IOException{
文件soxBinary=新文件(soXBinaryPath);
如果(!soxBinary.exists()){
抛出新的FileNotFoundException(“Sox二进制文件在以下路径下不可用:“+soXBinaryPath”);
}
添加(0,soXBinaryPath);
debug(“Sox参数:{}”,参数);
ProcessBuilder ProcessBuilder=新的ProcessBuilder(参数);
processBuilder.redirectErrorStream(true);
Process=null;
IOException errorDuringExecution=null;
试一试{
process=processBuilder.start();
BufferedReader=新的BufferedReader(新的InputStreamReader(process.getInputStream());
弦线;
而((line=reader.readLine())!=null){
logger.debug(行);
}
}捕获(IOE异常){
执行期间出错=e;
error(“运行Sox.{}时出错”,e.getMessage());
}最后{
参数。清除();
if(进程!=null){
process.destroy();
}
if(errorDuringExecution!=null){
执行时抛出错误;
}
}
}

第一步应该是在这些捕捉块中放置一些东西。到目前为止,您正在隐藏任何错误。@mattuck您是否先尝试过?嗨,凯文和乔治,非常感谢您的回复。我在catch()块中添加了一些消息,但它不返回任何错误。在运行try()之前,还尝试了open()函数。不幸的是没有运气。我想知道我如何判断它是否真的打开了SoX,以及
int exitVal=p.waitFor()中的错误代码1是什么意思;System.out.println(“带错误代码退出”+exitVal)