Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala eats exit code when piping stdin #4771

Closed
scabug opened this issue Jul 5, 2011 · 9 comments
Closed

Scala eats exit code when piping stdin #4771

scabug opened this issue Jul 5, 2011 · 9 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jul 5, 2011

A.scala:

 object A {
   def main(args:Array[String]) = System.exit(1)
 }

From a Bash shell:

% scala A; echo $?
1
% scala A < /dev/null; echo $?
0

In the second case, the exit code 1 disappears. Tried this with 2.8 and I don't have this problem.

@scabug
Copy link
Author

scabug commented Jul 5, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4771?orig=1
Reporter: Percy Liang (pliang)

@scabug
Copy link
Author

scabug commented Aug 4, 2011

Jonathan Clark (jhclark) said:
I also just stumbled upon this one and replicated the same issue, running a script that was not pre-compiled.

Scala 2.9.0-final. Ubuntu 10.04 LTS.

@scabug
Copy link
Author

scabug commented Aug 4, 2011

Jonathan Clark (jhclark) said:
Percy: I guess it figures the NLP researchers would discover anything wrong with stdin first. :-)

@scabug
Copy link
Author

scabug commented Aug 23, 2011

Jonathan Clark (jhclark) said:
I believe I might have found the cause, when exploring a seemingly unrelated issue (catching error codes from child bash processes). I believe the bug is at ProcessBuilderImpl.scala:72 -- in Simple.run(p: ProcessIO). Basically, scala always connects stdin to child processes, no matter what. However, piping /dev/null or the like to a child process (opening its input stream in any way), can cause it to behave differently. In my unrelated case, I cannot get bash to return proper return codes when it believes it is reading a script from stdin. My hypothesis is that the scala interpreter might have some similar magic like the bash interpreter. Any comments/suggestions from someone who knows the scala codebase a bit better?

@scabug
Copy link
Author

scabug commented Nov 24, 2011

Matthew Farwell (mfarwell) said:
This is fixed in trunk. In investigating Jenkins reporting success when Scala fails, this is a different aspect of the same problem.

The fix is simple, in $SCALA_HOME/bin/scala, line 25, change

function onExit() {
  if [[ "$saved_stty" != "" ]]; then
    restoreSttySettings
    exit $scala_exit_status
  fi
}

move the exit outside the test for $saved_stty.

function onExit() {
  if [[ "$saved_stty" != "" ]]; then
    restoreSttySettings
  fi
  exit $scala_exit_status
}

This has already been done in trunk, and this works with the latest build.

@scabug
Copy link
Author

scabug commented Nov 24, 2011

Matthew Farwell (mfarwell) said (edited on Mar 21, 2012 7:46:03 PM UTC):
I think this should be backported to 2.9.x because it seems like the script will swallow error codes in any environment where the script is run by a third party, such as jenkins, ant. I haven't tested maven.

@scabug
Copy link
Author

scabug commented Mar 21, 2012

@paulp said:
Pull request would do wonders.

@scabug
Copy link
Author

scabug commented Mar 21, 2012

Matthew Farwell (mfarwell) said:
Et voilà.

scala/scala#309

Sorry, should have done the pull request before.

@scabug
Copy link
Author

scabug commented Apr 16, 2012

@paulp said:
6f43d81942

@scabug scabug closed this as completed Apr 16, 2012
@scabug scabug added this to the 2.9.2 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants