Hello,
If Tcl's "exec" command is used to execute a command, how does one see
the exact command that is issued to the OS?
I'm asking this question because I'm investigating the failure of
statements such as:
set someDir C:[file nativename /Users]
exec -- cmd.exe /C cd $someDir && dir
which responds: "The system cannot find the path specified."
If I disable command extensions:
exec -- cmd.exe /E:OFF /C cd $someDir && dir
I don't get an error but I don't get the expected list of files either.
However, this command works as expected:
exec -- cmd.exe /C dir $someDir
so I'm thinking it has something to do with the &&, hence my question.
One more thing. Such commands did work a few months ago so something
has changed.
I see this on Windows 10 using both Tcl 8.6.9 and 8.6.12.
Thanks in advance for any help/insights.
-mike
Hello,Hello Mike,
If Tcl's "exec" command is used to execute a command, how does one see
the exact command that is issued to the OS?
I'm asking this question because I'm investigating the failure of
statements such as:
set someDir C:[file nativename /Users]
exec -- cmd.exe /C cd $someDir && dir
On 05/31/2022 1:08 PM, Michael Soyka wrote:
Hello,
If Tcl's "exec" command is used to execute a command, how does one see
the exact command that is issued to the OS?
I'm asking this question because I'm investigating the failure of statements such as:
   set someDir C:[file nativename /Users]
   exec -- cmd.exe /C cd $someDir && dir
which responds: "The system cannot find the path specified."
However, this alternative does work:
exec -- cmd.exe /C "cd $someDir && dir"
but I don't understand why.
If I disable command extensions:
   exec -- cmd.exe /E:OFF /C cd $someDir && dir
I don't get an error but I don't get the expected list of files either.
However, this command works as expected:
   exec -- cmd.exe /C dir $someDir
so I'm thinking it has something to do with the &&, hence my question.
One more thing. Such commands did work a few months ago so something has changed.
I see this on Windows 10 using both Tcl 8.6.9 and 8.6.12.
Thanks in advance for any help/insights.
-mike
Hello,Hello Mike,
If Tcl's "exec" command is used to execute a command, how does one see
the exact command that is issued to the OS?
I'm asking this question because I'm investigating the failure of
statements such as:
set someDir C:[file nativename /Users]
exec -- cmd.exe /C cd $someDir && dir
I think you need quotes: Try
exec -- cmd.exe /C "cd $someDir" && "dir"
or
exec -- cmd.exe /C "cd $someDir" && dir
both worked on my Windows 10, 64 bit system.
Note, that when 'exec' returns I was still in my original directory,
but I could of course 'cd' from within Tcl.
I don't know what you want to do but did you have a look at 'glob'?
HTH
Helmut
Hello Mike,
However, this alternative does work:
exec -- cmd.exe /C "cd $someDir && dir"
but I don't understand why.
I don't know how good your German is but here goes:
Hinweis: Mehrere Befehle, die durch das Befehlstrennzeichen "&&"
getrennt sind, werden als Zeichenfolge akzeptiert, wenn diese von Anführungsstrichen umgeben sind.
My translation: Note: Several commands separated by "&&" are accepted
when they are quoted. (short form)
HTH
Helmut
PS: I got this info by typing 'help cmd' in a console window.
However, this alternative does work:
exec -- cmd.exe /C "cd $someDir && dir"
but I don't understand why.
At Tue, 31 May 2022 15:07:31 -0400 Michael Soyka <[email protected]> wrote:
On 05/31/2022 1:08 PM, Michael Soyka wrote:
Hello,
If Tcl's "exec" command is used to execute a command, how does one see
the exact command that is issued to the OS?
I'm asking this question because I'm investigating the failure of
statements such as:
   set someDir C:[file nativename /Users]
   exec -- cmd.exe /C cd $someDir && dir
which responds: "The system cannot find the path specified."
However, this alternative does work:
exec -- cmd.exe /C "cd $someDir && dir"
but I don't understand why.
I'm guessing that "cmd.exe /C <mumble>" is MS-Windows's way of doing "sh -c <mumble>". My guess, like sh -c <mumble>, there are some gotchas relating to how you need to quote things. You want to create a subshell and run something like a pipeline there. You need to make sure the whole pipeline is passed to the subshell, so you need to make the pipeline *one* argument ("cd $someDir &&
dir"), not 4 arguments (cd, $someDir, &&, dir). If you don't, you end up passing just cd to cmd.exe /C, and then you have the three options "$someDir",
"&&", and "dir" leftover.
If I disable command extensions:
   exec -- cmd.exe /E:OFF /C cd $someDir && dir >>>
I don't get an error but I don't get the expected list of files either.
However, this command works as expected:
   exec -- cmd.exe /C dir $someDir
so I'm thinking it has something to do with the &&, hence my question.
One more thing. Such commands did work a few months ago so something
has changed.
I see this on Windows 10 using both Tcl 8.6.9 and 8.6.12.
Thanks in advance for any help/insights.
-mike
On 05/31/2022 3:50 PM, Robert Heller wrote:
At Tue, 31 May 2022 15:07:31 -0400 Michael Soyka <[email protected]> wrote:
On 05/31/2022 1:08 PM, Michael Soyka wrote:
Hello,
If Tcl's "exec" command is used to execute a command, how does one see >>> the exact command that is issued to the OS?
I'm asking this question because I'm investigating the failure of
statements such as:
ÃâàÃâàÃâàset someDir C:[file nativename /Users]
ÃâàÃâàÃâàexec -- cmd.exe /C cd $someDir && dir
which responds: "The system cannot find the path specified."
However, this alternative does work:
exec -- cmd.exe /C "cd $someDir && dir"
but I don't understand why.
I'm guessing that "cmd.exe /C <mumble>" is MS-Windows's way of doing "sh -c <mumble>". My guess, like sh -c <mumble>, there are some gotchas relating to
how you need to quote things. You want to create a subshell and run something
like a pipeline there. You need to make sure the whole pipeline is passed to
the subshell, so you need to make the pipeline *one* argument ("cd $someDir &&
dir"), not 4 arguments (cd, $someDir, &&, dir). If you don't, you end up passing just cd to cmd.exe /C, and then you have the three options "$someDir",
"&&", and "dir" leftover.
I agree that that appears to be true. However, the "exec" man page says
(to me) that each "exec" argument represents a subprocess. Under that assumption I don't understand why "cmd.exe", "/C" and the rest should be formatted as 3 Tcl words (neither 1 nor 2 work).
I'm reviewing what I think is the relevant Tcl source code
(tclWinPipe.c) but, so far, it's been tough sledding!
If I disable command extensions:
ÃâàÃâàÃâàexec -- cmd.exe /E:OFF /C cd $someDir && dir
I don't get an error but I don't get the expected list of files either. >>>
However, this command works as expected:
ÃâàÃâàÃâàexec -- cmd.exe /C dir $someDir
so I'm thinking it has something to do with the &&, hence my question. >>>
One more thing.ÃâàSuch commands did work a few months ago so something
has changed.
I see this on Windows 10 using both Tcl 8.6.9 and 8.6.12.
Thanks in advance for any help/insights.
-mike
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 714 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 136:56:36 |
| Calls: | 12,087 |
| Files: | 14,997 |
| Messages: | 6,517,384 |