6

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

T3 H40
  • 2,326
  • 8
  • 32
  • 43
solotim
  • 1,826
  • 4
  • 24
  • 41
  • 1
    In such a case, an example code would be of great help. – Riduidel Mar 29 '10 at 08:18
  • 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 '10 at 08: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 '10 at 09: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 '10 at 02:48

4 Answers4

8

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
  • 44,698
  • 7
  • 80
  • 103
4

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

    {"/bin/csh", "-cf", "echo hello"}
user85421
  • 28,957
  • 10
  • 64
  • 87
  • @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 '10 at 08:57
1

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
  • 42,753
  • 9
  • 87
  • 112
0

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

Community
  • 1
  • 1
Shervin Asgari
  • 23,901
  • 30
  • 103
  • 143