简体   繁体   English

从命令行运行 m 文件时如何隐藏“MATLAB 命令行窗口”?

[英]How do I hide “MATLAB Command Window” when I run an m-file from command line?

I am running MATLAB with a command line string like this:我正在使用如下命令行字符串运行 MATLAB:

C:\<a long path here>\matlab.exe -nodisplay -nosplash -nodesktop -r "run('C:\<a long path here>\mfile.m');"

The m-file contains a plot() function to plot a simple curve on the xy plane. m 文件包含plot() function 到 plot xy 平面上的简单曲线。

The m-file successfully runs and draws the plotting with the command line string I specified above. m 文件成功运行并使用我在上面指定的命令行字符串绘制绘图。 However, every time I run this command, a window named "MATLAB Command Window" appears along with the plotting.但是,每次我运行此命令时,都会出现一个名为“MATLAB 命令行窗口”的 window 以及绘图。

How do I make this "MATLAB Command Window" NOT appear, so that only the plotting will be visible.如何使此“MATLAB 命令行窗口”不出现,以便只有绘图可见。

The "MATLAB Command Window" looks like below: “MATLAB 命令行窗口”如下所示:在此处输入图像描述

Run:跑:

matlab -automation -wait -r "cd \'...\';..."

,which will show a minimized Window in the user session. ,这将在用户 session 中显示最小化的 Window。 By suggestion from Amro, we can send the minimized window to winlogin session locally so that we even cannot see the minimized Window:根据Amro的建议,我们可以将最小化的window发送到本地winlogin session,这样我们甚至看不到最小化的Window:

psexec /i 0 matlab -nodesktop -wait -r "plot(rand(100,1)); print -dpng out.png;quit" >null 2>&1

,which will save the figure to C:\Windows\System32 silently (if ISD service is enabled it may pop up an interactive services detection dialog window, and /s or /x option do not work in Windows server 2003 or 2008.) ,which will save the figure to C:\Windows\System32 silently (if ISD service is enabled it may pop up an interactive services detection dialog window, and /s or /x option do not work in Windows server 2003 or 2008.)

Great news!好消息!

With a bit of Java manipulation, it is possible!通过一点 Java 操作,这是可能的! Start MATLAB normally (with the desktop etc.) Now run setDesktopVisibility (false) and voila.正常启动 MATLAB(使用桌面等)现在运行setDesktopVisibility (false) 并瞧。 Eg例如

setDesktopVisibility(false);
mesh(rand(10));
pause;
setDesktopVisibility(true);

AFAIK you can't do it on Windows using the options with matlab.exe . AFAIK 你不能使用 matlab.exe 的选项在matlab.exe上做到这一点。 If you really need to hide it, I'd recommend using the MATLAB Engine to display your figure.如果你真的需要隐藏它,我建议使用MATLAB 引擎来显示你的身材。 Additionally, if it's for simple things like plotting, etc. you could use GNU Octave which works with M files and does not have a "Command Window" like MATLAB does (it runs in the Windows Command Prompt and hiding it is not that hard).此外,如果它是用于绘图等简单的事情,您可以使用GNU Octave ,它适用于 M 文件并且没有像 MATLAB 那样的“命令窗口”(它在 Windows 命令提示符中运行并隐藏它并不难) .

If you are a running Matlab from another program on Windows, you can run it using the Matlab COM Automation Server .如果您是从 Windows 上的另一个程序运行的 Matlab,您可以使用Matlab ZD47C174ED277BDF0CZFC 自动化服务器运行它。 The ActiveX control has a Visible property which will let you make the command window invisible, but looks like it leaves the plots visible. ActiveX 控件有一个 Visible 属性,可让您使命令 window 不可见,但看起来它使绘图可见。

Here's an example of how to do it using another Matlab as the controller.这是一个如何使用另一个 Matlab 作为 controller 的示例。

ml = actxserver('Matlab.Application');
ml.Visible = false;
ml.Execute('surf(peaks)');

Or in VBScript.或在 VBScript 中。

Set ml = CreateObject("Matlab.Application")
ml.Visible = false
ml.Execute("surf(peaks)")
ml.Execute("pause(4)")

This interaction mode might be more what you want anyway, depending on how your workflow is structured, because it'll let you fire up the Matlab process once and make many plot requests on it, saving startup costs and letting you have multiple plots visible at once.无论如何,这种交互模式可能更符合您的需求,具体取决于您的工作流程的结构,因为它可以让您启动 Matlab 进程并在其上发出许多 plot 请求,从而节省启动成本并让您在一次。

If you still want to call it from a command line, just run it through a.vbs wrapper script with the above VBScript code, but call run('...\mfile.m') instead of surf(peaks) .如果您仍想从命令行调用它,只需使用上述 VBScript 代码通过 a.vbs 包装脚本运行它,但调用run('...\mfile.m')而不是surf(peaks) Your mfile.m will need some GUI logic that makes it block until the user dismisses the plot, replacing the pause call, so it doesn't disappear before they're done viewing it.您的 mfile.m 将需要一些 GUI 逻辑,使其阻塞,直到用户关闭 plot,替换pause调用,因此在他们完成查看之前它不会消失。

com.mathworks.mde.desk.MLDesktop.getInstance.closeCommandWindow

You can probably use it from the command-line as:您可能可以从命令行使用它:

-r "com.mathworks.mde.desk.MLDesktop.getInstance.closeCommandWindow; run('C:\<a long path here>\mfile.m');"

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

相关问题 如何运行 Windows 批处理文件但隐藏命令窗口? - How can I run a windows batch file but hide the command window? 在将参数传递给 PS 文件时,如何使用 invoke-command 从 windows 命令行运行 PS 文件? - How do I use invoke-command to run a PS file from the windows command line while passing parameters to the PS file? 如何从命令行在 Windows 上运行 .class 文件? - How do I run .class files on windows from command line? 如何在python命令行中运行.py文件? - how do I run my .py file from within python command line? 如何关闭从命令行创建的文件? - How do I close a file created from command line? 我如何从命令行知道 macOS 有英特尔芯片(或)m1 芯片? - How do I know macOS has intel chip (or) m1 chip from command line? 如何在不打开新 cmd 窗口的情况下从命令行启动程序? - How do I launch a program from command line without opening a new cmd window? 如何从sh脚本打开新的命令行窗口,然后传入多个命令 - How do I open a new command line window from an sh script and then pass in multiple commands 从命令提示符或Windows 7/8跳转列表菜单打开sln文件时,如何添加默认的“以管理员身份运行”? - How do I add a default Run As Administrator when I open a sln file from the command prompt or Windows 7/8 Jump List menu? 如何创建脚本以运行MySQL命令行? - How do I create a script to run MySQL command line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM