MBS ShellMBS vs. WindowProcessMBS

Since the answer to this would be of use to any MBS user on Windows, I want to ask @Christian Schmitz for clarification of the difference between these two classes and how they should be used. As a starting point, I use this code in a Window PushButton’s Action Event:

[code]// Dim tShell As New ShellMBS
Dim tShell As New WindowsProcessMBS

// Simplest form of the WindowsProcessMBS way -
tShell.CommandLine = “cmd /c mtx -f \\.\changer0 status”
If tShell.Run Then
Window1.TextArea1.AppendText tShell.ReadOutput(tShell.AvailableBytesOutput)
Else
Window1.TextArea1.AppendText tShell.ReadError(tShell.AvailableBytesError)
End If
Do
Window1.TextArea1.AppendText tShell.ReadOutput(tShell.AvailableBytesOutput)
Loop Until Not tShell.Running
[/code]
However, when I run this, a back end process is kicked off that never returns, the False leg of the initial If block is fired, but I get no output in either Output or Error and results in the need to reboot the system to clear that process.

I’m obviously missing the point somewhere. So, what did I miss?

Windows 10 Pro, Xojo 18r1, MBS 19r2pr8

Note - I have checked the command and it does run properly in a cmd.exe ConHost instance.

First ShellMBS and WindowProcessMBS are nearly the same. But ShellMBS adds the Mac/Linux parts.

So run method returns false?
I wonder whether you may need to provide full app path as there is no cmd to evaluate PATH environment variable.

Thanks. That’s what I thought you’d said,but I wanted clarification.

Any idea why the hung process?

[quote=437265:@Christian Schmitz]So run method returns false?
I wonder whether you may need to provide full app path as there is no cmd to evaluate PATH environment variable.[/quote]
Yes - Rebooting to try that.

Same result - The call to tShell.Run results in False immediately, but the process that was launched never exits. However, I can now “End Task” it and not reboot to clear it.

I updated the code above as I was calling “cmd /c” in the actual code.

When using ShellMBS, I don’t get the hung background process, but still no output and the call to .Execute returns immediately with %ERRORLEVEL% == 2. The other change is that even though the exe being called, I’m not being prompted to authroize the run (it’s set to “Run as administrator”) like I am in the WindowsProcessMBS call of the same command.

what about Shell class?
Feel free to email me something to test here.

did you try quoting the command line?

tShell.CommandLine = "cmd /c ""mtx -f \\\\.\\changer0 status"""

Here’s copy and paste from the test app’s Button Action event:

[code]Dim tShell As New ShellMBS
// Dim tShell As New WindowsProcessMBS

// tShell.Username = “Administrator”
// tShell.CommandLine = “cmd /c “”\ProgramData\TOLIS Group\BRU PE\bin\mtx.exe”" -f \\.\changer0 status"
tshell.ApplicationName = “BRU MTX”
// tShell.Executable = “C:\ProgramData\TOLIS Group\BRU PE\bin\mtx.exe”
// tShell.Arguments.Append “-f \\.\Changer0”
// tShell.Arguments.Append “status”
tShell.Arguments.Append “–version”
tShell.CurrentDirectory = “C:”
// tShell.Environment.Value(
tShell.Execute(“cmd /c ““C:\ProgramData\TOLIS Group\BRU PE\bin\mtx.exe”””)
// If tShell.Run Then
// Window1.TextArea1.AppendText tShell.ReadOutput(tShell.AvailableBytesOutput)
// Else
// Window1.TextArea1.AppendText tShell.ReadError(tShell.AvailableBytesError)
// End If

Do
App.DoEvents(5)
tShell.Poll
// Window1.TextArea1.AppendText tShell.ReadOutput(tShell.AvailableBytesOutput)
Window1.TextArea1.AppendText tShell.ReadOutput
Loop Until Not tShell.IsRunning
Window1.TextArea1.AppendText "Run completed - $ERRORLEVEL% = " + Str(tShell.ErrorCode)
[/code]