我想從Unix(bash)命令行向以下Java程序發送文本輸入,以便打印輸入的文本。我如何編寫一個shell腳本將字符串「Print this」發送到Java程序?使用shell腳本寫入程序的標準輸入
import java.util.Scanner;
public class ReadStuff{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println("Enter some text:");
System.out.println(scan.nextLine());
}
}
如果你的程序只在命令行中輸入的需要,那麼你就可以按照這種方式:http://docs.oracle.com/javase /tutorial/essential/environment/cmdLineArgs.html –
我需要修改程序(因爲它目前存在於此頁面上)才能使其運行? –
是的,你必須。 –