MBS ShellMBS vs. WindowProcessMBS

  1. 3 months ago

    Tim J

    May 19 Pre-Release Testers, Xojo Pro Dehydrating in AZ
    Edited 3 months ago

    Since the answer to this would be of use to any MBS user on Windows, I want to ask @ChristianSchmitz 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:

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

    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

  2. Tim J

    May 19 Pre-Release Testers, Xojo Pro Dehydrating in AZ

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

  3. Christian S

    May 19 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

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

  4. Christian S

    May 19 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    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.

  5. Tim J

    May 19 Pre-Release Testers, Xojo Pro Dehydrating in AZ

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

    Any idea why the hung process?

  6. Tim J

    May 19 Pre-Release Testers, Xojo Pro Dehydrating in AZ

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

    Yes - Rebooting to try that.

  7. Tim J

    May 19 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    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.

  8. Tim J

    May 19 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    @ChristianSchmitz I wonder whether you may need to provide full app path as there is no cmd to evaluate PATH environment variable.

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

  9. Tim J

    May 19 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    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.

  10. Christian S

    May 19 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

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

  11. Christian S

    May 19 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    did you try quoting the command line?

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

    May 19 Pre-Release Testers, Xojo Pro Dehydrating in AZ
    Edited 3 months ago

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

    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)

or Sign Up to reply!