2013-11-25 87 views
0

我想從Java發送下面的命令成功在linux從Java發送命令到Linux

[email protected]

此命令改變hylafax爲發送傳真 調制解調器,並運行此命令在Linux的shell 但是當它與Java運行如下:

modemcommand = "[email protected]"; 
    InputStreamReader isr = null; 

    try { 

     isr = new InputStreamReader(Runtime.getRuntime().exec(modemcommand).getInputStream()); 

     System.out.println("The Command : "+modemcommand+" is running successfull!"); 
    } catch (IOException ex) { 
     System.out.println("The Command : "+modemcommand+" is not running successfull!"); 
     System.out.println("Error on switch to modem : "+Modem+" :--> "+ex.toString()); 
     System.out.println("--------------------------------------------------------------"); 

    } 

輸出爲:誤差= 2:沒有這樣的文件或目錄 有人能幫助我嗎?

+0

這只是一個命令,當某些shell解釋時,所以你的意思是'sh FAXSERVER = ...';但是這可能仍然不能解決你的問題,因爲環境變量的作用域是shell進程(沒有全局設置)。 –

回答

0

您只是將名爲FAXSERVER的環境變量設置爲值[email protected],但不提供要執行的命令的名稱。使用類似

modemcommand = "[email protected] my_command"; 
+0

感謝lutz爲你回覆 – Tishk

+0

但這個命令在shell中運行 – Tishk

+0

沒有命令。您只爲shell命令設置了一個永不會到來的環境變量。 – 2013-11-25 13:13:40