我正在使用ProcessBuilder从我的Java代码执行curl,它什么都不返回。我在Mac上从终端尝试了相同的curl命令,它运行正常,并根据curl输出创建文件。 curloutput.txt是空白的,我运行程序后没有创建file1.txt,因为它没有得到任何回复。
ProcessBuilder process = new ProcessBuilder("/usr/bin/curl", "-H" ,"'Accept: application/json'", "-H","'Content-Type: application/json'",
"-X", "POST", "-d","'{\"args\":", "{\"uid\":", uid,"\"token\":",token,
"\"api-token\":",apitoken,"\"json-strict-mode\":","false,", "\"json-verbose-response\":","false}}'",
url,">>","file1.txt");
Process p;
try
{
process.redirectOutput(new File("curloutput.txt"));
p = process.start();
p.waitFor();//added based on Earlybird's suggestion
}
catch (IOException e)
{ System.out.print("error");
e.printStackTrace();
}