hello - a bit new to xojo (but do have other language experience) so please bear with me…
I am trying to work with the shell class to execute psexec (of the PsTools suite which you can google if you are not familiar) and also redirect psexecs remote output to a file. This is done via normal command line by the following (with some additional flags that may not be necessary - but still work):
psexec.exe \\COMPUTERNAME -u USERNAME -p PASSWORD -s -h -accepteula -nobanner cmd.exe /c dir >>c:\temp\remote.log
This command will do a directory listing on a remote computer and output that directory listing to c:\temp\remote.log
However, if I run the following code in xojo - it only outputs the first line:
Dim s as Shell
s = New Shell
s.Mode = 0
s.TimeOut = -1
s.Execute(“psexec.exe \\COMPUTERNAME -u USERNAME -p PASSWORD -s -h -accepteula -nobanner cmd.exe /c dir >>c:\temp\remote.log”)
I am assuming that the “shell” that xojo uses is not exactly the legit windows shell and it cannot handle the >> redirection properly. Would it be possible for someone else to confirm this for me? Or perhaps suggest another way that I can use output redirection with psexec. Psexec is a bit different than other tools because it has both local output and remote output. I can very easily capture the local output with s.Result but very much need to rely on >> to capture the remote output. Any help is much appreciated!
Beatrix - capturing .result and NOT using the >> redirection only seems to capture the first line of the REMOTE output - but it does capture all of the LOCAL output - for example:
the local output might look something like this:
Connecting to 192.168.1.26...
Starting PSEXESVC service on 192.168.1.26...
Connecting with PsExec service on 192.168.1.26...
Starting cmd.exe on 192.168.1.26...
cmd.exe exited on 192.168.1.26 with error code 0.
NOTE: all of this output is captured correctly and fully
While the remote output looks like this:
Volume in drive C has no label.
NOTE: only the FIRST LINE of this output is captured - this is the first line that you would see if you issued the “dir” command - and the rest of the output is MIA
I assume this might either have to do with how PSEXEC handles its remote output or how xojo uses the shell. Either way I was hopefully that maybe someone else might of had experience specifically with working with PSEXEC inside of xojo or maybe other tips with how to handle shell output.
What happens if you use the Shell in Mode 1, and use the DataAvailable event to capture the output (into a text area or something). Does it capture only the first line, or does it capture all of it?
does it work if you execute these separately, into two different output files?[/quote]
Jeff - Nope - its actually one giant statement - you set certain flags with psexec to execute a specific command on a remote computer. The remote command we are executing is “cmd.exe /c dir” but all of this is written as one statement.
[quote=305827:@Jukka Leino]Is there some switch in psexec.exe to wait for remote process to complete.
It might be that xojo stops when psexec stops, but remote is not ready…[/quote]
Jukka - nope - not that I am aware of - it might be that the way it returns data makes xojo think that after the first line it is done.
[quote=305837:@Michel Bujardet]Unless psexec.exe is next to your executable, you need to precede it with the full path.
Xojo shell does not use the path environment variable like the command prompt does.[/quote]
Michel - for ease of this demo, I have actually put the psexec.exe with my app. But yes I am also using full paths and it is actually executing the psexec.exe - just not fully returning everything.
Greg - Yup I did and no error - however, I was experiencing a timeout earlier (before I knew about the timeout property) - is there a listing somewhere for ALL the shell error codes and their meanings? Might be something good to have for reference in the future.
[quote=305831:@Neil Burkholder]You might try this instead for windows.
dim s as new OLEObject("WScript.Shell")
dim s1 as OLEObject = s.run(CommandString)
[/quote]
Neil - this is an interesting approach that I am giving a try - a cmd window opens over the app to run psexec but I am not sure if its timing out or throwing an error before it finishes but I do capture the following OLEException error - “No automation server present” - Any ideas?