This is related to How to execute a remote command and pass in local file as input?
I wrote a simple Java program that prints the first line of a file -
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.OutputStreamWriter;
public class ReadFirstLine
{
public static void main(String[] args) throws Exception
{
String filename = args[0];
BufferedReader iR = new BufferedReader (new FileReader(filename));
BufferedWriter oW = new BufferedWriter(new OutputStreamWriter(System.out));
outputWriter.write(iR.readLine());
iR.close();
oW.close();
}
}
Then, I created a symlink in the /usr/bin directory called ReadFirstLine
which points to the /usr/local/RFL/ReadFirstLine script -
#! /bin/bash
java -cp "/usr/local/RFL" ReadFirstLine "$1"
(/usr/local/RFL has ReadFirstLine.class)
Now, I can call ReadFirstLine from any directory like this -
$ ReadFirstLine simplefile.txt
This same script I want to call from a different machine. So from the remote machine I tried -
$ ssh username@xyz ReadFirstLine < localfile.txt
However, I got the error
Exception in thread "main" java.io.FileNotFoundException: (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at java.io.FileReader.<init>(FileReader.java:58)
at ReadFirstLine.main(ReadFirstLine.java:12)
How can I modify the Java Program / script such that this remote invocation works?
head -1
? – cuonglm Apr 14 '14 at 17:47