ralph
3/17/2011 5:25:00 PM
On Thu, 17 Mar 2011 16:38:35 +0000, MM <kylix_is@yahoo.co.uk> wrote:
>On Thu, 17 Mar 2011 06:51:11 -0500, ralph <nt_consulting64@yahoo.net>
>wrote:
>
>>On Thu, 17 Mar 2011 07:20:35 +0000, MM <kylix_is@yahoo.co.uk> wrote:
>>
>>>On vbmonster.com you wrote:
>>>
>>><quote>
>>>What you need to do is invoke a secondary command processor. There's
>>>simply no other way to use redirection or pipes in a command line...
>>>
>>>retval = ExecCmd(Environ("comspec") & " /k " & App.Path & "\test.exe "
>>>& txtTestName.Text & ".cfg > x:\somepath\results.txt")
>>>
>>>The /k will keep the window open. When you have it working, change
>>>that to /c.
>>></quote>
>>>
>>>Can you elucidate a bit here, as I am having great difficulty passing
>>>a command line via ExecCmd (i.e. using CreateProcess) on Windows 2000.
>>>If the command line I pass contains a " > ", the ERRORLEVEL comes back
>>>as "faulty command line". I have tried every possible combination of
>>>quotes. Why does the redirection symbol > screw it up?
>>>
>>>MM
>>
>>You will likely have better results using Shell() compared to
>>CreateProcess().
>>
>>However, you might show your declarations and code for assembling the
>>command line.
>
>SourceFile = "c:\mm\progs\par2join\thefiles.avi.par2"
>OutputFile = "c:\temp\temp.txt"
>
>This doesn't work:
>lRet = ExecCmd("c:\utils\par2 v" & Chr$(34) & SourceFile & Chr$(34) &
>" > " & Chr$(34) & OutputFile & Chr$(34))
>
>
>This does work:
>
>lRet = ExecCmd("c:\utils\par2 v" & Chr$(34) & SourceFile & Chr$(34))
>
>(i.e. not using redirection)
>
>
>This doesn't work (using Jim Mack's caret to escape the >):
>
>lRet = ExecCmd("c:\utils\par2 v" & Chr$(34) & SourceFile & Chr$(34) &
>" ^> " & Chr$(34) & OutputFile & Chr$(34))
>
>but it doesn't work either.
>
>Note: par2.exe is a command line DOS executable alternative to
>QuickPAR. The v switch means verify.
>
>MM
Well ... as one of the best ways to get a lot of people responding is
to say something stupid - I'm going to do you a favor and respond with
a "less than technical, more superstitional" comment (ie, stupid). <g>
I vaguely remember having trouble with this before and my solution was
to use Shell() whenever I needed to do redirection or otherwise create
a compound 'command line' expression.
My rational was simply ... CreateProcess and its irk, are for spawning
or creating processes not for command line processing. (whatever the H
that means <smile>). The same goes pipes and such, if I needed a pipe
I either used the Api to make one, or I used Shell and the command
line pipe.
I think Mr. Mack has something there, but forget the details (assuming
I ever knew them). I think I did once, but it doesn't matter as here
is my rule:
1) Complex or non-trivial *command line* string for a dos Prompt - use
Shell.
2) Complex or non-trival *create a process" - use CreateProcess.
If you are doing a "Shell and Wait", while many examples show using
CreateProcess(), you can just as easy use Shell() to accomplish the
same thing.
-ralph