2015-09-21 18 views
2

我想運行一個J腳本,提供STDIN,並通過STDOUT接收腳本的輸出。如何向通過jconsole.exe運行的J腳本提供STDIN數據?

我覺得我失去了一些非常明顯的東西,但help pages on using jconsole.exe是。 。 。簡潔。

我天真的想法是,我可以運行在cmd.exe的外殼下面提供STDIN:

jconsole.exe script.ijs inputstring 

雖然這個作品,未經嘗試STDIN:

C:\..\bin>jconsole.exe "C:\path\no-input-script.ijs" 
success 
C:\..\bin> 

no-input-script.ijs文件如下:

stdout 'success' 
exit '' 

我有以下的script-with-input.ijs文件:

input =: stdin '' 
stdout 'input was ' , input 
exit '' 

當我運行以下,系統掛起:

C:\..\bin>jconsole.exe "C:\path\script-with-input.ijs" xyz 

當我隨後打按Ctrl + Ç,腳本會退出,我留下了以下內容:

C:\..\bin>jconsole.exe "C:\path\script-with-input.ijs" xyz 
input was 
C:\..\bin> 

回答

4

stdin讀取直到EOF(通常以* NI從STDIN輸入x^D)。所以你的'script-with-input.ijs'等待用戶輸入或管道。

c:>jconsole.exe "script-with-input.ijs" hello 
this is user input 
^D 
input was this is user input 

你要做的就是讀取命令的參數。這些都存儲在ARGV:

NB. script-with-input.ijs 
input =: ARGV 
echo input 
exit'' 

然後:

c:>jconsole.exe "script-with-input.ijs" hello 
┌────────────┬─────────────────────┬─────┐ 
│jconsole.exe│script-with-input.ijs│hello│ 
└────────────┴─────────────────────┴─────┘ 
+0

你不介意與「你好」管道的一個例子擴大你的回答給我的腳本與 - input.ijs?如果它被傳入,我的腳本會像預期的那樣行事嗎? – Dane

+2

我無法在Windows上驗證這一點,但以下應該工作:1.重定向輸入'jconsole script.ijs Eelvex

相關問題