这样的事情的等效命令我不知道哪个是调用批处理命令的正确形式
def proc =["/bin/sh", "-c","curl https://stackoverflow.com"]
proc.waitFor()
StringBuffer outputStream = new StringBuffer()
proc.waitForProcessOutput(outputStream, System.err)
String output = outputStream.toString()
答案 0 :(得分:1)
为什么不考虑使用java.net.URL?
示例代码在这里
{this.props.dog_url}
,如果你想从java调用curl命令,请使用下面的
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Hello{
public static void main(String []args){
try
{
URL url = new URL("http://stackoverflow.com");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"))) {
for (String line; (line = reader.readLine()) != null;) {
System.out.println(line);
}
}
}
catch (Exception e)
{
System.out.println("error occured");
}
}
}
答案 1 :(得分:1)
您可以从Java生成进程:
Activity