したがって、クライアントとサーバーの Java プログラムがあります。クライアントは Java processbuilder を使用してスクリプトを実行しますが、私の問題は、ユーザーが bash スクリプトに渡す必要がある情報を入力することです。したがって、基本的には、3 つの異なる文字列を、bash スクリプトによって読み取られる 3 つの異なる変数に送信する方法を知る必要があります。このスクリプトはファイルをコピーしているので、java で txt ファイルを作成せず、スクリプトにファイルを読み取らせます。また、これを OS X と Windows で実行できるようにしたいので、改善を歓迎します。現在、UbuntuでJava 7を使用しています。
ここに私がやろうとしていることのスニペットがあります: .java
Scanner bob = new Scanner(System.in);
String workingDirectory = new String(System.getProperty("user.dir"));
File tempDir = new File(workingDirectory);
String script = new String(workingDirectory + "/copyjava.sh");
System.out.print("Designate the location of the file: ");
String loc = bob.next();
System.out.print("Type the name of the file w/ extension: ");
String name = bob.next();
System.out.print("What is the location of THIS file? "); //I know there is a way to do this automagically but I can't remember how...
String wkspace = bob.next();
ProcessBuilder pb = new ProcessBuilder( script, loc, name, wkspace);
pb.start();
File myFile = new File (name);
脚本:
read loc
read name
read wkspace
cd $LOC
cp $name $wkspace