首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有输出到Java进程的标准输出

问没有输出到Java进程的标准输出
EN

Stack Overflow用户
提问于 2018-08-25 14:29:15
回答 1查看 162关注 0票数 0

我正在执行mysql.exe form a java进程(在Windows10,JDK1.8env中),代码如下:

代码语言:javascript
复制
String command="D:\\SW\\MySQL_8\\bin\\mysql.exe --user=root --password=password";

ProcessBuilder pBuilder=new ProcessBuilder(command.split(" "));
pBuilder=pBuilder.redirectOutput(new File("D:\\workspaces\\cas\\CASCAppliance_Common\\out\\out.txt"));
pBuilder=pBuilder.redirectError(new File("D:\\workspaces\\cas\\CASCAppliance_Common\\out\\err.txt"));

Process p=pBuilder.start();
OutputStream os=p.getOutputStream();
PrintWriter writer=new PrintWriter(os);

如果我从命令行执行mysql.exe,我会得到以下输出:

代码语言:javascript
复制
Microsoft Windows [Version 10.0.17134.228]
(c) 2018 Microsoft Corporation. All rights reserved.

D:\SW>cd MySQL_8\bin

D:\SW\MySQL_8\bin>mysql --user=root --password=password
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.11 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

我尝试在错误流重定向后从进程中获取输入流,得到的结果如下:

代码语言:javascript
复制
mysql: [Warning] Using a password on the command line interface can be insecure.

我还尝试将err和std out重定向到文件,err文件仍然包含上述文本,而std out文件不包含任何内容。

另一方面,如果我执行cmd.exe并运行一个命令,比如'dir',我将从进程的InputStream中获得所需的目录列表。

我的问题是,是我做错了什么,还是mysql.exe的执行方式不可能从进程的输入流中获得上述输出。

EN

回答 1

Stack Overflow用户

发布于 2018-08-25 15:32:12

是的,这是关于mysql的。(编辑是来自@dave_thompson_085的更新)

如果用户从交互式shell运行mysql,但是重定向输入和/或输出,它将禁止横幅、提示、表格装箱和'N row(s) (X sec)‘尾部。

注即使没有提示,它仍然读取SQL语句并执行它们,并显示任何结果集--尽管如果输出是它缓冲的管道。相反,如果在终端上有stdin和stdout的Java进程中,运行继承了这些的mysql,它就具有完全的交互行为。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52014636

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档