【发布时间】:2018-01-28 18:02:44
【问题描述】:
我正在尝试从 Java 运行 Linux 命令。该命令从命令行本身运行完美,但从 Java 却没有。 命令行的命令是
curl -H "Content-Type: text/plain" -d "$(printf '#Genes\nPIK3C2A\nPTEN\nUNC5B')" -X POST --url https://reactome.org/AnalysisService/identifiers/projection/
来自Java的命令是
String $notifyMsg="\"$(printf '#Genes\nPIK3C2A\nPTEN\nUNC5B')\"";
String $reactome = "https://reactome.org/AnalysisService/identifiers/projection/";
String $notifyTitle= "\"Content-Type: text/plain\"";
String $command = "curl" + " " + "-H"+ " " + $notifyTitle + " "+ "-d " + $notifyMsg +" "+ "-X" + " " + "POST" + " " + " " + "--url" +" " + $reactome;
System.out.println("Command is: " + $command);
Process p=Runtime.getRuntime().exec($command);
p.waitFor();
System.out.println("Run Result " + p.exitValue() )
我应该得到这样的输出
{"summary":{"token":"MjAxODAxMjMxNjQyMDZfNjcy","projection":true,"interactors":false,"type":"OVERREPRESENTATION","sampleName":"Genes","text":true},"expression":{"columnNames":[]},"identifiersNotFound":0,"pathwaysFound":51,"pathways":
但是我得到 0 。谁能告诉我可能出了什么问题?
【问题讨论】:
-
考虑使用 jsoup 或 apache http 组件或任何其他 Java 库。你不需要在这里使用 curl。
-
当有许多本地 Java 库可以执行此操作时,为什么要通过启动
curl来下载文件?