[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Karl, back in 2005 you wrote about redirection in command line...

(Mike Mitchell)

3/17/2011 7:21:00 AM

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
13 Answers

ralph

3/17/2011 11:51:00 AM

0

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.

-ralph

Jim Mack

3/17/2011 11:59:00 AM

0

MM wrote:
>
> 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?

It's been a while, but this is my recollection...

As a rule, you have to 'escape' special characters in a command line.
The escape character in this context is a caret ^ symbol.

So a > becomes ^>, which should be seen as a plain > by the CLI.

--
Jim Mack
Support Wisconsin! http://www.cafepress.com/2050i...

(Mike Mitchell)

3/17/2011 4:39:00 PM

0

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

Bob Butler

3/17/2011 5:02:00 PM

0


"MM" <kylix_is@yahoo.co.uk> wrote in message
news:7ld4o690e1hv629hv72n7svgii5am3ebdp@4ax.com...
<cut>
> This doesn't work:
> lRet = ExecCmd("c:\utils\par2 v" & Chr$(34) & SourceFile & Chr$(34) &
> " > " & Chr$(34) & OutputFile & Chr$(34))

You aren't doing what was suggested:

>><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>

Note the part about 'Environ("comspec")'



ralph

3/17/2011 5:25:00 PM

0

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

(Mike Mitchell)

3/17/2011 5:25:00 PM

0

On Thu, 17 Mar 2011 10:02:27 -0700, "Bob Butler"
<bob_butler@cox.invalid> wrote:

>
>"MM" <kylix_is@yahoo.co.uk> wrote in message
>news:7ld4o690e1hv629hv72n7svgii5am3ebdp@4ax.com...
><cut>
>> This doesn't work:
>> lRet = ExecCmd("c:\utils\par2 v" & Chr$(34) & SourceFile & Chr$(34) &
>> " > " & Chr$(34) & OutputFile & Chr$(34))
>
>You aren't doing what was suggested:

I tried it.

>
>>><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>
>
>Note the part about 'Environ("comspec")'

Froze VB6 IDE solid.

MM

ralph

3/17/2011 5:33:00 PM

0

On Thu, 17 Mar 2011 10:02:27 -0700, "Bob Butler"
<bob_butler@cox.invalid> wrote:

>
>"MM" <kylix_is@yahoo.co.uk> wrote in message
>news:7ld4o690e1hv629hv72n7svgii5am3ebdp@4ax.com...
><cut>
>> This doesn't work:
>> lRet = ExecCmd("c:\utils\par2 v" & Chr$(34) & SourceFile & Chr$(34) &
>> " > " & Chr$(34) & OutputFile & Chr$(34))
>
>You aren't doing what was suggested:
>
>>><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>
>
>Note the part about 'Environ("comspec")'
>

That's IT!

What you need to spawn is the DOSPrompt process with args, not the
application.

-ralph

(nobody)

3/17/2011 5:37:00 PM

0

Search the newsgroups for "vb SetStdHandle" for a cleaner solution.


Karl E. Peterson

3/17/2011 5:58:00 PM

0

on 3/17/2011, MM supposed :
>> Note the part about 'Environ("comspec")'
>
> Froze VB6 IDE solid.

BS. <g>

--
..NET: It's About Trust!
http://vfre...


Karl E. Peterson

3/17/2011 6:02:00 PM

0

on 3/17/2011, MM supposed :
> On vbmonster.com you wrote:

Nope. Not me. They probably sucked on msnews for that.

> <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.

Why are you using CreateProcess rather than Shell?

Why aren't you starting a command processor? (Redirection is a
conceptual thing that only makes sense in context -- ie, within a
command processor.)

If you insist on using CreateProcess, you may indeed need to set the
standard output handle for the process, as Nobody suggests.

--
..NET: It's About Trust!
http://vfre...