Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

执行commands有问题 #19

Open
Chersh-Pan opened this issue Apr 28, 2015 · 8 comments
Open

执行commands有问题 #19

Chersh-Pan opened this issue Apr 28, 2015 · 8 comments

Comments

@Chersh-Pan
Copy link

for (String command : commands) {
if (command == null) {
continue;
}

            // donnot use os.writeBytes(commmand), avoid chinese charset error
            os.write(command.getBytes());
            os.writeBytes(COMMAND_LINE_END);
            os.flush();
        }

当传入的commands数组过大,os write将近64M的字节时会出现错误

@Chersh-Pan
Copy link
Author

64K的数据

@Trinea
Copy link
Owner

Trinea commented Apr 28, 2015

是指 command.getBytes() 很大?
具体什么错误?OOM?

@Chersh-Pan
Copy link
Author

os.write的数据不能超过64K,也就是如果commands数组过大就会出现错误

@Trinea
Copy link
Owner

Trinea commented Apr 29, 2015

没拿这么大的数据测试过,什么场景要这么多命令,分开执行不行吗

@Chersh-Pan
Copy link
Author

可以也可以,只是这个存在这个问题

@Trinea
Copy link
Owner

Trinea commented Apr 29, 2015

ok,没时间细看这个问题,你有时间的话,也可以提交 PR 修复这个问题

@Chersh-Pan
Copy link
Author

主要是process.getOutputStream()这个流有限制大小,改不了吧

@ComeOn-Wuhan
Copy link

发现常常死等在waitfor
我看别人都是写成线程的异步
new Thread() {
public void run() {
BufferedReader br2 = new BufferedReader(new InputStreamReader(is2));
try {
String line2 = null ;
while ((line2 = br2.readLine()) != null ) {
if (line2 != null){}
}
} catch (IOException e) {
e.printStackTrace();
}
finally{
try {
is2.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}.start();

是不是那样处理就会更好点?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants