tags:

views:

362

answers:

4

Hi, everybody. I invoked shell command by Process class of java and it gave "stty: standard input: Invalid argument" no matter 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 shows. I can't figure out why.

Command is something lik this {"/bin/csh", "-c", "echo hello"}

Thanks

+1  A: 

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.

Jonathan Feinberg
Thanks, but what blah stands for?
solotim
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.
EJP
A: 

Quoth the documentation for 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."

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

msw
Thanks. But actually I used ProcessBuilder too, it turns out the same results.
solotim
A: 

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

Shervin
+1  A: 

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

    {"/bin/csh", "-cf", "echo hello"}
Carlos Heuberger
It may work. But user may not like this.
solotim
@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...
Carlos Heuberger