【发布时间】:2014-09-13 09:23:45
【问题描述】:
如果我们每天需要将大约 30G 文件(从 50MB 到 4GB)上传到 Google Cloud Storage,根据 google 文档,gsutil 可能是唯一合适的选择,不是吗?
我想通过 Java 调用 gsutil 命令,现在下面的代码可以工作了。但是如果我删除那个while循环,程序将在runtime.exec(command)之后立即停止,但是python进程已经启动但没有上传,它很快就会被杀死。我想知道为什么。
我从 sterr 流中阅读的原因是受到 Pipe gsutil output to file 的启发
我通过 read util 其状态输出的最后一行来决定 gsutil 是否完成执行,但这是一种可靠的方法吗?有没有更好的方法来检测 gsutil 执行是否在 Java 中结束?
String command="python c:/gsutil/gsutil.py cp C:/SFC_Data/gps.txt"
+ " gs://getest/gps.txt";
try {
Process process = Runtime.getRuntime().exec(command);
System.out.println("the output stream is "+process.getErrorStream());
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s;
while ((s = reader.readLine()) != null){
System.out.println("The inout stream is " + s);
}
} catch (IOException e) {
e.printStackTrace();
}
【问题讨论】: