简体   繁体   English

java Processbuilder-执行OS X上不在路径中的文件

[英]java Processbuilder - exec a file which is not in path on OS X

Okay i'm trying to make ChucK available in exported Processing sketches, ie if i export an app from Processing, the ChucK VM binary will be executed from inside the app. 好的,我正在尝试使ChucK在导出的Processing草图中可用,即,如果我从Processing中导出一个应用程序,则ChucK VM二进制文件将从该应用程序内部执行。 So as a user of said app you don't need to worry about ChucK being in your path at all. 因此,作为该应用程序的用户,您完全不必担心ChucK在您的操作中。

Right now i'm generating and executing a bash script file, but this way i don't get any console output from ChucK back into Processing: 现在,我正在生成并执行一个bash脚本文件,但是通过这种方式,我不会将ChucK的任何控制台输出返回到Processing中:

#!/bin/bash
cd "[to where the Chuck executable is located]"
./chuck --kill
killall chuck # just to make sure
./chuck chuckScript1.ck cuckScriptn.ck

then 然后

Process p = Runtime.getRuntime().exec("chmod 777 "+scriptPath);
p = Runtime.getRuntime().exec(scriptPath);

This works but i want to run ChucK directly from Processing instead, but can't get it to execute: 这有效,但是我想直接从Processing运行ChucK,但是不能执行它:

String chuckPath = "[folder in which the chuck executable is located]"
ProcessBuilder builder = new ProcessBuilder
                              (chuckPath+"/chuck", "test.ck");

        final Process process = builder.start();
        InputStream is = process.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line;
        while((line = br.readLine()) != null) println(line);
        println("done chuckin'! exitValue: " + process.exitValue());

Sorry if this is newbie style :D 抱歉,如果这是新手风格:D

ProcessBuilder builder = new ProcessBuilder
                              (chuckPath+"/chuck", chuckPath+"/test.ck");

the args all need an absolute path. args都需要绝对路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM