简体   繁体   中英

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.

    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. 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?

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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