Tuesday, October 2, 2012

VNC viewer: copy and paste text

If you are unable to copy text from and to a VNC client to your windows operating system, make sure the vncconfig application is running on the remote server.

Run "vncconfig &" from the vncviewer, and check all checkboxes.

From Unix to Windows from a VNC session:
1) Highlight the text you want to copy by holding down the left mouse button and dragging, just like in Windows. This copies it to the Windows clipboard.
2) Go to your Windows window and paste it from the clipboard as usual.

By the way, to paste it into the Unix window, put your cursor where you want it to go, then click the middle mouse button.

Reference:
http://www.unix.com/windows-dos-issues-discussions/40732-vnc-copy-paste-problem.html

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

Run Java console application by double click

Assume you have written a console java application in Eclipse and want to distribute it to users as an executable. You export the class files as an executable JAR file from eclipse, however to run the JAR file you need to use Windows Command Prompt and type in the command
java -jar Filename.jar arguments

To make it more easily runnable - by a double click - we need to create a .bat file with the following contents  and present in the same folder as the JAR file.

@echo off
 set jarpath="JavaApp.jar"
 java -jar %jarpath% %CD%Config.txt
 PAUSE

Here, %CD% is a pseudo-variable which holds the working directory. It’s useful when you want to load a config file located in the same folder as your .bat file. You can also replace it with any arguments for the JAR file. PAUSE displays a localized version of “Press any key to continue…” message.

References:
http://blog.mwrobel.eu/how-to-properly-run-java-consol-application-with-a-doubleclick-windows/