Re: Shell Command Doesn't Create TXT file as expected
- From: "Andibevan" <Andibevan@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 7 Sep 2005 14:36:32 +0100
<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
.
- References:
- Shell Command Doesn't Create TXT file as expected
- From: Andibevan
- Shell Command Doesn't Create TXT file as expected
- Prev by Date: NewLine in an ini entry
- Next by Date: Re: Native Code vs PCode OT
- Previous by thread: Re: Shell Command Doesn't Create TXT file as expected
- Next by thread: Barcode GIF or JPEG
- Index(es):
Relevant Pages
|