[英]Display prompt in a shell run from Java ProcessBuilder
I run a sh
shell process like this: 我运行这样的sh
shell进程:
ProcessBuilder pb = new ProcessBuilder();
pb.command("sh");
Process p = pb.start();
and then I push commands into its OutputStream and read output from its InputStream. 然后将命令推入其OutputStream并从其InputStream读取输出。 All works fine - I have a shell. 一切正常-我有一个外壳。
However the shell has no prompt. 但是 ,shell没有提示。 If I run "sh" on the device through adb, I get a prompt. 如果通过adb在设备上运行“ sh”,则会出现提示。 I can change the prompt using PS1=blah
. 我可以使用PS1=blah
更改提示。 But when sh
is run from ProcessBuilder
, no prompt. 但是当从ProcessBuilder
运行sh
时,没有提示。
How can I make the prompt appear please? 我如何使提示出现?
The trick is to force the shell to run in 'interactive' mode - equivalent to using sh -i
: 诀窍是迫使shell以“交互”模式运行-等同于使用sh -i
:
ProcessBuilder pb = new ProcessBuilder();
pb.command("sh", "-i");
Process p = pb.start();
That works, but unfortunately complains about not being able to find a tty fd. 那行得通,但不幸的是抱怨找不到tty fd。 I can live with that for now. 我现在可以忍受。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.