I tried to make a wrapper to fcsh. The wrapper will have a socket open so that users can use netcat to talk to it. Possible usage would be like:
$ java FcshServer /opt/adobe/flex/bin/fcsh
$ echo "compile Game.as" | nc localhost 8081
Then FcshServer will see if Game.as has been already compiled. If it has, incremental compilation will be used. So far, I can wrap fcsh and send user inputs to stdin of fcsh and redirect fcsh's stdout to console.
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStreamReader;
public class FcshServer {
public static void main(String argv[]) throws IOException {
if(argv.length < 1) {
System.out.println("Usage: java FcshServer path/to/fcsh");
System.exit(1);
}
//run fcsh
Process fcsh = new ProcessBuilder(argv).start();
//redirect stdout of fcsh to here
OutThread fcshout = new OutThread(fcsh);
fcshout.start();
//prepare for read from stdin of this.
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
String line = new String("");
PrintWriter fcshin = new PrintWriter(fcsh.getOutputStream());
while(fcshout.isAlive() && null != (line = in.readLine())) {
fcshin.println(line);
fcshin.flush();
}
in.close();
fcshin.close();
}
}
class OutThread extends Thread {
private BufferedReader stdin;
OutThread(Process p) throws IOException {
stdin = new BufferedReader(
new InputStreamReader(p.getInputStream()));
}
public void run() {
int c;
try {
while((c = stdin.read()) != -1) {
System.out.print((char)c);
}
System.out.println("Press Enter to exit.");
} catch(IOException e) {
e.printStackTrace();
}
}
}
Hello Mister. I am very interested in what you are doing with the fcsh server. I like the quickness of fsch but I want to be able to have automation. Email me at philip aat philmaker doot com and we can be friends. Thanks to you.
ReplyDeleteHi. My last message was a little strange - was tired last night. I am really interested in getting this working robustly so give me a shout at philip at philmaker dot com.
ReplyDeleteThanks,
Phil
I started an fcsh server project from scratch at: http://code.google.com/p/mac-applescript-devtool/downloads/list
ReplyDeleteOK thanks. I'll stop leaving you messages. :-)