I am having a problem with a shell that I cannot figure out. I am trying to communicate with a CLI app via shell like this:
Dim s As New Shell
s.Mode = 2
s.Execute("C:\\Users\\Administrator\\Desktop\\PIOSOL~1.10\\PIOSOL~2.EXE")
Now this works fine but when the program loads it gives me an error saying it cannot initialize as it cannot find any of its pref/dat files that are located in the same folder. If I just open the .exe it works fine but when I execute via a shell it will not. I think it has something to do with how shell paths work but not really sure.
The shell doesn’t inherit any of your normal environment’s settings and the tool may be depending on some of those settings. If it’s just the tool’s associated resources, what happens if you cd into the folder first:
Dim s As New Shell
s.Mode = 2
s.Execute("cd C:\\Users\\Administrator\\Desktop\\PIOSOL~1.10\\ & .\\PIOSOL~2.EXE")
After I run that command I am still not able to send/receive data from the shell using Mode 2. I put the send routines in a thread with a timer monitoring the DataAvailable/ReadAll event. I have the thread “waiting” with a while/wend and a me.sleep(100) waiting for data from the timer. It does not seem to execute any of the Write commands. Any ideas on what I am doing wrong?
Otherwise your Windows shell times out in 2 seconds.
and
YOU must manage the shell mechanism when you create one in that manner. You don’t get the DataAvailable and Completed events. Therefore, you must exec the command and then loop until your process is done, outputting info to the user and getting user input.
You must treat it much like a Console app while you’re locked onto the shell’s I/O:
Dim theShell As New Shell
theShell.Mode = 2
theShell.Timeout = -1
theShell.Execute theCommand
Do
theShell.Poll
theMethodToReadProcessOutput()
theMethodToGetUserInput()
theMethodToUpdateTheUI()
App.DoEvents(10)
Loop Until Not theShell.IsRunning
If this is done in a Thread, Change App.DoEvents(10) to Me.Sleep(10).
Without the App.DoEvents() in the loop, even Timers become unresponsive.