[英]Run already opened process in vb.net
I have a windows form that, on the click of a button, runs a process (MATLAB) and executes a file. 我有一个Windows窗体,只需单击一个按钮,即可运行一个进程(MATLAB)并执行一个文件。
Dim myProcesses() As Process
myProcesses = Process.GetProcessesByName("Matlab")
If myProcesses.Count > 0 Then
'~~~~ what goes here? ~~~~
Else
Dim startInfo As New ProcessStartInfo
startInfo.FileName = "C:\Program Files\MATLAB\R2011b\bin\matlab.exe"
startInfo.WorkingDirectory = MatlabDir 'MatlabDir is defined elsewhere
startInfo.Arguments = "matlab.exe -r test_plot2"
Process.Start(startInfo)
End If
The above code opens MATLAB and executes the script "test_plot2.m" if MATLAB isn't already open. 上面的代码将打开MATLAB并在尚未打开MATLAB的情况下执行脚本“ test_plot2.m”。 But what do I write in the first IF statement, if MATLAB is already open, and all I want to do is run the file?
但是,如果MATLAB已经打开,而我想做的就是运行文件,那么我应该在第一条IF语句中写什么呢?
Thanks in advance. 提前致谢。
Its supposed to be the same. 它应该是相同的。 I mean, it doesn't matter if its opened or not, unless the application (Matlab) manages something different, then you have to guess how.
我的意思是,是否打开它并不重要,除非应用程序(Matlab)管理其他内容,否则您必须猜测如何做。 Have you tried just using the same code?
您是否尝试过使用相同的代码?
Example: 例:
Dim startInfo As New ProcessStartInfo
startInfo.FileName = "notepad.exe"
startInfo.Arguments = "C:\temp\test.txt"
Process.Start(startInfo)
It doesn't matter if you have Notepad already opened or not. 记事本是否已打开都没有关系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.