我想运行一个 J 脚本,提供 STDIN,并使用 STDOUT 接收脚本的输出。
我觉得我错过了一些非常明显的东西,但是使用 jconsole.exe的帮助页面是 . . . 简洁。
我天真的想法是我可以在 cmd.exe shell 中运行以下命令来提供 STDIN:
jconsole.exe script.ijs inputstring
Run Code Online (Sandbox Code Playgroud)
虽然这在没有尝试 STDIN 的情况下有效:
C:\..\bin>jconsole.exe "C:\path\no-input-script.ijs"
success
C:\..\bin>
Run Code Online (Sandbox Code Playgroud)
该no-input-script.ijs
文件如下:
stdout 'success'
exit ''
Run Code Online (Sandbox Code Playgroud)
我有以下script-with-input.ijs
文件:
input =: stdin ''
stdout 'input was ' , input
exit ''
Run Code Online (Sandbox Code Playgroud)
当我运行以下命令时,系统挂起:
C:\..\bin>jconsole.exe "C:\path\script-with-input.ijs" xyz
Run Code Online (Sandbox Code Playgroud)
当我然后点击Ctrl+ 时C,脚本退出,我留下以下内容:
C:\..\bin>jconsole.exe "C:\path\script-with-input.ijs" xyz
input was
C:\..\bin>
Run Code Online (Sandbox Code Playgroud)
stdin
从 STDIN 读取输入直到 EOF(通常在 *nix ^D 中)。所以你的 'script-with-input.ijs' 等待用户输入或管道。
c:>jconsole.exe "script-with-input.ijs" hello
this is user input
^D
input was this is user input
Run Code Online (Sandbox Code Playgroud)
相反,您要做的是读取命令的参数。这些存储在 ARGV 中:
NB. script-with-input.ijs
input =: ARGV
echo input
exit''
Run Code Online (Sandbox Code Playgroud)
然后:
c:>jconsole.exe "script-with-input.ijs" hello
??????????????????????????????????????????
?jconsole.exe?script-with-input.ijs?hello?
??????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)