Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 - getting the status of shell 1

Status
Not open for further replies.

sandtek

Programmer
Nov 20, 2007
13
SG
Hi All,
Im a writing a simple aps and here I want to execute a command and get the status of the command I spawned.
Say, I want to delete a file

Code:
Shell "del somefile.txt", vbNormalFocus
msgbox "Status is OK"

The problem here is the Msgbox will appear/executed in parallel with
the command I have just executed from Shell. What I want is the Msgbox will wait until the del command finishes and if possible, get the status of that command after it is executed (OK / NotOK). Is this possible? Or is there any other way around to get this done? Thanks in advance.

 
Thanks HughLerwill, but the del command was just an example. Sorry for the confusion. My goal is actually
to establish an sftp connection between my local machine to a remote server (UNIX). I tried to find some libraries for sftp from vb but I can't seem to find any. So my last option is to spawn an external program (psftp.exe) and let it do the action. And as a good programming practice, a confirmation scheme for an action executed should also packaged in the application but I can't do it in shell.

Thanks in advance.
 
Add a reference to the Windows Script Host Object Model, and use the WhsSHell's Exec method, which returns a WshExec object
 
The Exec method and the WshScriptExec object it returns can certainly be handy, but I find at least two limitations in this approach.

For one thing it results in a console window if you run a command line utility. It can also be somewhat "clunky" to interact with in VB6 because it doesn't raise events to reflect the presence of responses.

In the WSH documentation they use Sleep loops as an example of how you might poll for output back from the child process. This has its issues in a VB6 Form, so I'd probably use a Timer control to drive this polling instead.


I needed to do this very sort of thing myself some time ago. I wasn't doing file transfers but I had to interact with remote systems using Telnet and SSH. For lack of SSH-oriented components for VB6 I decided to "automate" PLink in much the same manner you describe for PSFTP.

Later I needed to do FTP, SFTP, and FTPS transfers too.

So I ended up packaging CreateProcess and StdIO redirection into a UserControl for doing this. It has proven pretty useful.

This "ShellPipe" control also uses a Timer for polling in order to be compatible with Win9x systems. Today it could be updated to use async I/O but I haven't had the need to change it. The interaction model is much like using a Winsock control to talk to a remote server.

You can find a recent version of it in the sample Project at capture "java -version" data in VB.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top