代码
Process p = Runtime.getRuntime().exec("python .\\py\\Crawler.py \"arg1\" \"arg2\" );
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while((line = reader.readLine()) != null){
System.out.println(line);
}
上述代码等同于在shell中运行命令
“python .\py\Crawler.py 'arg1' 'arg2'”
需要注意的是在Java中构造命令是,引用参数的是双引号,而非单引号。若用单引号,导致的问题是:python脚本获取的参数是'arg1'而非arg1的形式,切记切记!