Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

bash

csh

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

like image 527
solotim Avatar asked Mar 29 '10 08:03

solotim


3 Answers

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.

like image 91
Jonathan Feinberg Avatar answered Oct 21 '22 09:10

Jonathan Feinberg


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

    {"/bin/csh", "-cf", "echo hello"}
like image 34
user85421 Avatar answered Oct 21 '22 08:10

user85421


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.

like image 1
msw Avatar answered Oct 21 '22 09:10

msw