简体   繁体   English

如何在 ImageJ 中使用 exec 命令运行 cmd 命令并在外部 cmd window 中显示打印输出/进度(非无头)

[英]How to run cmd command with exec command in ImageJ and show printout/progress in external cmd window (not headless)

I want to start an R sript from imageJ macro (IJM language) and do this using the exec command.我想从 imageJ 宏(IJM 语言)启动一个 R 脚本并使用 exec 命令执行此操作。 exec(path_to_R path_to_script); this script takes a long time to run, and I would like to monitor the progress of it at runtime.这个脚本需要很长时间才能运行,我想在运行时监控它的进度。 However the cmd window is not open, and I only get the print statements in the imageJ log when the script is compleated.但是 cmd window 没有打开,我只有在脚本完成后才能在 imageJ 日志中得到打印语句。 Is there a way to show the cmd window while the scrip is running?有没有办法在脚本运行时显示 cmd window ?

I am running this script on both Windows 7 and Windows 10我在 Windows 7 和 Windows 10 上运行此脚本

Two simple test examples are:两个简单的测试示例是:

exec('cmd /c "help"'); # That I want to very quickly show the help output, but now it is returned to imageJ log after compleation # 那个我想很快显示帮助output,但是现在完成后返回到imageJ日志

and exec('cmd /c "Timeout 5"');exec('cmd /c "Timeout 5"'); # That I want to have as a separate cmd window that is open for 5 seconds. # 我想作为一个单独的 cmd window 打开 5 秒。

I have attempted to open a second cmd from the one that is started from ImageJ, but could not find the correct syntax.我试图打开从 ImageJ 启动的第二个 cmd,但找不到正确的语法。 I tried eg exec('cmd start cmd /c Timeout 5');我试过例如exec('cmd start cmd /c Timeout 5'); but nothing happens但什么也没发生

As I wrote this question I figured it out.当我写这个问题时,我想通了。 I was missing an /c in the first cmd call.我在第一个 cmd 调用中缺少 /c 。

The function exec('cmd /c start cmd /c Timeout 5'); function exec('cmd /c start cmd /c Timeout 5'); will call cmd open a new cmd that is being shown and show this window for 5 seconds.将调用 cmd 打开正在显示的新 cmd 并显示此 window 5 秒钟。

I hope this can help someone else我希望这可以帮助别人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM