Showing posts with label command prompt. Show all posts
Showing posts with label command prompt. Show all posts

Tuesday, October 2, 2012

redirect STDIN, STDOUT and STDERROR

You can redirect STDIN, STDOUT and STDERRORs when running applications from the shell (or command prompt).

To redirect STDIN, use "<". The command looks like:
$ some-command < /path/to/some/file

To redirect STDOUT, use ">". The command looks like:
$ some-program > /path/to/some/file

To append STDOUT redirect output use ">>".The command looks like:
$ some-program >> /path/to/some/file

To redirect STDERR, you need to know about File Descriptors (FD). Check the reference for additional details. You need to use "n>&m" operator. It means to redirect FD n to the same places as FD m. Eg, 2>&1 means send STDERR to the same place that STDOUT is going to. The command looks like
$ some-program >> /path/to/some/file 2>&1

Reference:
1. http://www.linuxsa.org.au/tips/io-redirection.html

Add external jar files in classpath when running Java programs from command prompt or shell

If you simply want to compile or run Java applications from command line, you can just add the jars to the classpath:
javac -classpath c:\path1\ext1.jar;d:\path2\ext2.jar de\example\MyClass.java

When running a java application, you have to add the classes folder as well
java -classpath bin;c:\path1\ext1.jar;d:\path2\ext2.jar de.example.MyClass

When running from command prompt on windows, you can also replace "bin" with a "."

Note that under *nix OS not a semicolon(;), but a colon(:) is used to separate classpath parts.

Reference:
1. http://www.coderanch.com/t/423052/java/java/solved-add-external-jar-windows