添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

"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.

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

I did nothing but very simple things to invoke "echo hello" from java. This code acutually runs ok several weeks ago, so I think something wrong with my bash recently, not java – solotim Mar 29, 2010 at 8:38 i believe there are ways in Java to perform operating system functions and there is no need to call system commands. what command are you calling that Java doesn't have a module for that? – ghostdog74 Mar 29, 2010 at 9:11 Well, I want to create a shell embeded in java. User can input any shell command and java will execute them and return stdout/stderr to java gui. – solotim Mar 30, 2010 at 2:48

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

stty blah blah blah 2>/dev/null

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

It doesn't matter what it stands for. Invoking stty in a context where there isn't a tty, such as an exec'd process, is wrong. You can't do it. – user207421 Mar 29, 2010 at 9:15 @solotim: why not? anyway, if it works, it's an indication that the .cshrc or the .login script is trying to adjust the terminal without checking if there is one. The next step should be to add this check to the scripts... – user85421 Mar 30, 2010 at 8:57

"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."

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

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.