如何通过 jconsole.exe 向 J 脚本 运行 提供 STDIN 数据?

How do I provide STDIN data to a J script run via jconsole.exe?

我想 运行 一个 J 脚本,提供 STDIN,并使用 STDOUT 接收脚本的输出。

我觉得我错过了一些非常明显的东西,但 help pages on using jconsole.exe 是。 . .简洁。

我天真的想法是,我可以 运行 cmd.exe shell 中的以下内容来提供 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 时,脚本退出,我留下以下内容:

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

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

相反,您要做的是读取命令的参数。这些存储在 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│
└────────────┴─────────────────────┴─────┘