With command redirection one can redirect standard streams like stdin, stdout and stderr to user-specified locations. Quite often it is useful to redirect the output of a program to a text file.

  • redirecting stdout to a file

    someProgram >/some/where/output.txt (Linux/Unix Bash) someProgram >c:\some\where\output.txt (Windows command prompt)

  • redirecting stderr to a file

    someProgram 2>/some/where/output.txt (Linux/Unix Bash) someProgram 2>c:\some\where\output.txt (Windows command prompt)

  • redirecting stdout and stderr to a file

    someProgram &>/some/where/output.txt (Linux/Unix Bash) someProgram >c:\some\where\output.txt 2>&1 (Windows command prompt)

Note: under Weka quite often the output is printed to stderr, e.g., if one is using the -p 0 option from the commandline to print the predicted values for a test file:

 java weka.classifiers.trees.J48 -t train.arff -T test.arff -p 0 2> j48.txt

or if one already has a trained model:

 java weka.classifiers.trees.J48 -l j48.model -T test.arff -p 0 2> j48.txt


One can perform a basic redirection also in the SimpleCLI, e.g.:

 java weka.classifiers.trees.J48 -t test.arff > j48.txt

Note: the > must be preceded and followed by a space, otherwise it is not recognized as redirection, but part of another parameter.