Re: Shell Command Doesn't Create TXT file as expected




<Snip>


it is created, consider one of these (which makes
> your program wait until the DOS process is finished):
>
> MICROSOFT 'S OFFICIAL WAY
> ========================
> See this link
>
> http://support.microsoft.com/support/kb/articles/Q129/7/96.asp
>
> Note: This method doesn't use Shell -- it uses CreateProcessA.
>
>
> FAST AND DIRTY METHOD (WORKS ALMOST ALL THE TIME)
> =================================================
> Paste these lines in the (General)(Declarations) section of the form
> where the Shell is being called (or remove the Private keywords and put
> them in a BAS module if more than one form will use them):
>
> Private Declare Function OpenProcess _
> Lib "kernel32" _
> (ByVal dwDesiredAccess As Long, _
> ByVal bInheritHandle As Long, _
> ByVal dwProcessId As Long) As Long
> Private Declare Function CloseHandle _
> Lib "kernel32" _
> (ByVal hObject As Long) As Long
> Private Declare Function WaitForSingleObject _
> Lib "kernel32" _
> (ByVal hHandle As Long, _
> ByVal dwMilliseconds As Long) As Long
>
> Call your Shell command in this form with the appropriate Shell
> arguments placed in the parentheses:
>
> PID = Shell( <<Put Shell Arguments Here>> )
>
> And finally, paste the following IMMEDIATELY after the PID=Shell
> statement above (making sure to handle the possible error where
> indicated; i.e. stop the code from falling through to your other
> commands if the Shell failed):
>
> If PID = 0 Then
> '
> 'Handle Error, Shell Didn't Work
> '
> Else
> hProcess = OpenProcess(&H100000, True, PID)
> WaitForSingleObject hProcess, -1
> CloseHandle hProcess
> End If
>
>

Thanks for the very helpful information - I have your suggested "Quick and
Dirty" approach and that works in my tests.

I also tried to use the suggested MS approach with a different command (I
didn't actually need this technique for DIR) - Do you know if the MS
Approach will work when trying to writer the output of a command to a file?
I think some minor modifications may be required but I am not sure what?

Thanks

Andi


.



Relevant Pages

  • Re: Shell function - accessing an Access secure db (.MDW file)
    ... > Hi - Does anyone know the correct syntax for the shell function. ... You can use the Shell command. ... To execute internal DOS command (Dir, Copy, ... Private Declare Function OpenProcess _ ...
    (microsoft.public.vb.general.discussion)
  • Re: Shell to Command
    ... >> manually start a dos session and type in the command line ftp, ... Am I missing something in the shell function? ... To execute internal DOS command (Dir, ... > Private Declare Function OpenProcess _ ...
    (microsoft.public.vb.syntax)
  • Re: Shell to Command
    ... >> manually start a dos session and type in the command line ftp, ... Am I missing something in the shell function? ... To execute internal DOS command (Dir, ... > Private Declare Function OpenProcess _ ...
    (microsoft.public.vb.syntax)
  • Re: More difficult question - how do I wait until another application closes?
    ... another window (MS-DOS window). ... This method doesn't use Shell -- it uses CreateProcessA (and provides ... Private Declare Function OpenProcess _ ... WaitForSingleObject hProcess, -1 ...
    (comp.lang.basic.visual.misc)
  • Re: VB6 Shell Question
    ... stderr, but due to the complexity of my command, it doesn't execute. ... My shell command essentially ends up as: ... To execute internal DOS command (Dir, ... > Private Declare Function OpenProcess _ ...
    (microsoft.public.vb.general.discussion)