0

I am trying to use the screen command on linux. I need to print the stdout that I get in a normall shell command to a separate file after a detached session is done. How can I do so?

In particular, I am trying to run Weka experiments in screen and I need the results in a seperate file. For instance, the results of the following?

screen java weka.classifiers.bayes.NaiveBayes -t data.arff -x 10 

When I am not using screen I simply get the results using:

java weka.classifiers.bayes.NaiveBayes -t data.arff -x 10 > file.output
TrnKh
  • 758
  • 1
  • 7
  • 13

1 Answers1

0

You could always simply run the command not directly, but via shell:

screen bash -c "java weka.classifiers.bayes.NaiveBayes -t data.arff -x 10 > file.output"

Alternatively, one can use the built-in screen session logging. Unfortunately, screen isn't particularly smart and somewhat buggy, thus one has to resort to trickery to allow setting a custom output file. The best way I could come up with is as follows.

Create special configuration file, e.g. ~/.screenrc-redir. Content is just single line:

logfile $OUTFILE

Now, in bash prompt, redirection could be accomplished like this:

OUTFILE=file.output screen -L -c ~/.screenrc-redir <your-command>

What it does, is start screen with logging redirection, and send the output of the session to the file specified by the environment variable name.

Theoretically, the -L on command line could be replaced with the log on in the configuration file. But that for whatever reason doesn't work. Probably a bug in the screen.

Dummy00001
  • 16,630
  • 5
  • 41
  • 63