从java调用shell,它抱怨“stty:标准输入:无效参数”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2536531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 09:01:13  来源:igfitidea点击:

Invoking shell from java, it complaints "stty: standard input: Invalid argument"

javabashcsh

提问by solotim

I invoke a shell command by Process class from java and it prints

我从 java 中通过 Process 类调用 shell 命令并打印

"stty: standard input: Invalid argument" 

no matter whether the command is right or wrong (normal output of shell command is shown too). If I run the shell command in shell, no such error message is shown.

不管命令是对是错(shell命令的正常输出也有显示)。如果我在 shell 中运行 shell 命令,则不会显示此类错误消息。

The command is something like this: {"/bin/csh", "-c", "echo hello"}

命令是这样的: {"/bin/csh", "-c", "echo hello"}

采纳答案by user85421

Try using the -foption of csh to disable the reading of the .chsrc and .login files:

尝试使用-fcsh 选项禁用读取 .chsrc 和 .login 文件:

    {"/bin/csh", "-cf", "echo hello"}

回答by Jonathan Feinberg

You are invoking the sttycommand from your .profile, or .bash_profile. You'll have to redirect its standard error to /dev/null.

您正在stty.profile, 或调用命令.bash_profile。您必须将其标准错误重定向到/dev/null.

stty blah blah blah 2>/dev/null

stty can't deal with the pseudo-tty that Java provides in shelling out.

stty 无法处理 Java 在 shell 中提供的伪 tty。

回答by msw

Quoth the documentation for java.lang.Process:

引用java.lang.Process的文档:

"The methods that create processes may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts. The created subprocess does not have its own terminal or console."

“创建进程的方法可能不适用于某些原生平台上的特殊进程,例如原生窗口进程、守护进程、Microsoft Windows 上的 Win16/DOS 进程或 shell 脚本。创建的子进程没有自己的终端或控制台.”

Perhaps you would like the java.lang.ProcessBuilder, instead.

也许您更喜欢java.lang.ProcessBuilder

回答by Shervin Asgari

Have you look here. I managed to run some commands like this

你看看这里。我设法运行像一些命令