Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Remember the good old days, when CPU was singular?


devel / comp.lang.tcl / Puzzling "exec" behavior in Windows 10

SubjectAuthor
* Puzzling "exec" behavior in Windows 10Michael Soyka
+* Re: Puzzling "exec" behavior in Windows 10Michael Soyka
|+* Re: Puzzling "exec" behavior in Windows 10Helmut Giese
||`- Re: Puzzling "exec" behavior in Windows 10Michael Soyka
|`* Re: Puzzling "exec" behavior in Windows 10Robert Heller
| `* Re: Puzzling "exec" behavior in Windows 10Michael Soyka
|  `- Re: Puzzling "exec" behavior in Windows 10Robert Heller
`* Re: Puzzling "exec" behavior in Windows 10Helmut Giese
 `- Re: Puzzling "exec" behavior in Windows 10Michael Soyka

1
Puzzling "exec" behavior in Windows 10

<t75i39$tlf$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19434&group=comp.lang.tcl#19434

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mssr953@gmail.com (Michael Soyka)
Newsgroups: comp.lang.tcl
Subject: Puzzling "exec" behavior in Windows 10
Date: Tue, 31 May 2022 13:08:56 -0400
Organization: self
Lines: 33
Message-ID: <t75i39$tlf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 31 May 2022 17:08:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9f46c0399580f0cfc781bb3ccee242bc";
logging-data="30383"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Z4EydNWaflOt3er8/w0uR"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:20ULoUCkSNjykeV8gMb//Sp87Ig=
Content-Language: en-US
 by: Michael Soyka - Tue, 31 May 2022 17:08 UTC

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

Re: Puzzling "exec" behavior in Windows 10

<t75p1k$mbi$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19438&group=comp.lang.tcl#19438

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mssr953@gmail.com (Michael Soyka)
Newsgroups: comp.lang.tcl
Subject: Re: Puzzling "exec" behavior in Windows 10
Date: Tue, 31 May 2022 15:07:31 -0400
Organization: self
Lines: 42
Message-ID: <t75p1k$mbi$1@dont-email.me>
References: <t75i39$tlf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 31 May 2022 19:07:32 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9f46c0399580f0cfc781bb3ccee242bc";
logging-data="22898"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19sBDi31Tt4dsMFuhwLpwCR"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:cpqopyA1WQ4x7rXVtFBhoRNj52k=
In-Reply-To: <t75i39$tlf$1@dont-email.me>
Content-Language: en-US
 by: Michael Soyka - Tue, 31 May 2022 19:07 UTC

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

Re: Puzzling "exec" behavior in Windows 10

<csqc9hpl5gn4s900e5pje9p5tkmsdpvuh1@4ax.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19441&group=comp.lang.tcl#19441

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: Puzzling "exec" behavior in Windows 10
Date: Tue, 31 May 2022 21:31:20 +0200
Organization: ratiosoft
Lines: 22
Message-ID: <csqc9hpl5gn4s900e5pje9p5tkmsdpvuh1@4ax.com>
References: <t75i39$tlf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="ff6abadadc9502505c497efb1165b287";
logging-data="15750"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18zJluBNPJ7UKVHO3d/pS30"
Cancel-Lock: sha1:e7WTFymR1YWwPrurJGvszQlqKkc=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
 by: Helmut Giese - Tue, 31 May 2022 19:31 UTC

>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
Hello Mike,
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

Re: Puzzling "exec" behavior in Windows 10

<ebrc9hhpdpeqdc37bje8le33pd0m320e2m@4ax.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19442&group=comp.lang.tcl#19442

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: Puzzling "exec" behavior in Windows 10
Date: Tue, 31 May 2022 21:38:24 +0200
Organization: ratiosoft
Lines: 18
Message-ID: <ebrc9hhpdpeqdc37bje8le33pd0m320e2m@4ax.com>
References: <t75i39$tlf$1@dont-email.me> <t75p1k$mbi$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="ff6abadadc9502505c497efb1165b287";
logging-data="24111"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19wmhTOolHXsraCgBIwSqP+"
Cancel-Lock: sha1:/yR9gKMTfjF/BZJdcYppL9RaJaI=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
 by: Helmut Giese - Tue, 31 May 2022 19:38 UTC

>
>However, this alternative does work:
>
> exec -- cmd.exe /C "cd $someDir && dir"
>
>but I don't understand why.
>
Hello Mike,
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.

Re: Puzzling "exec" behavior in Windows 10

<7NudnfumW40W7Av_nZ2dnUU7-Q_NnZ2d@giganews.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19443&group=comp.lang.tcl#19443

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 31 May 2022 14:50:35 -0500
MIME-Version: 1.0
From: heller@deepsoft.com (Robert Heller)
Organization: Deepwoods Software
X-Newsreader: TkNews 3.0 (1.2.12)
Subject: Re: Puzzling "exec" behavior in Windows 10
In-Reply-To: <t75p1k$mbi$1@dont-email.me>
References: <t75i39$tlf$1@dont-email.me> <t75p1k$mbi$1@dont-email.me>
Newsgroups: comp.lang.tcl
Content-Type: text/plain;
charset="us-ascii"
Originator: heller@sharky4.deepsoft.com
Message-ID: <7NudnfumW40W7Av_nZ2dnUU7-Q_NnZ2d@giganews.com>
Date: Tue, 31 May 2022 14:50:35 -0500
Lines: 64
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-hGjLzbK4pwU6HvvK8C58g5qLdJlAumlZ/i+9wUM2NxPrpWvyRmTXa6z8XooJKelfirxlM1XPoEi2PFc!2XJUeRhuDqLQAv96p9bGawt3C9LtV5ccYgV3FkntGNr/tGVkW0ANkLXcPuzHBj339UV6FL0g8QFh!YAM=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 3414
 by: Robert Heller - Tue, 31 May 2022 19:50 UTC

At Tue, 31 May 2022 15:07:31 -0400 Michael Soyka <mssr953@gmail.com> 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
>
>
>

--
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
heller@deepsoft.com -- Webhosting Services

Re: Puzzling "exec" behavior in Windows 10

<t75sho$q3u$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19444&group=comp.lang.tcl#19444

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mssr953@gmail.com (Michael Soyka)
Newsgroups: comp.lang.tcl
Subject: Re: Puzzling "exec" behavior in Windows 10
Date: Tue, 31 May 2022 16:07:19 -0400
Organization: self
Lines: 31
Message-ID: <t75sho$q3u$1@dont-email.me>
References: <t75i39$tlf$1@dont-email.me>
<csqc9hpl5gn4s900e5pje9p5tkmsdpvuh1@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 31 May 2022 20:07:20 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9f46c0399580f0cfc781bb3ccee242bc";
logging-data="26750"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tnGfUoxgIKwyUIGwDa7Yi"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:mbUAfd2Ofg4OYwQh2pCn3CBK5ok=
In-Reply-To: <csqc9hpl5gn4s900e5pje9p5tkmsdpvuh1@4ax.com>
Content-Language: en-US
 by: Michael Soyka - Tue, 31 May 2022 20:07 UTC

On 05/31/2022 3:31 PM, Helmut Giese 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
> Hello Mike,
> 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'?

Thanks Helmut for the suggestion but my example is misleading.

My goal is to use a single shell to execute a sequence of commands. I
crafted the above example to demonstrate the problem with as simple an
example as I could.

>
> HTH
> Helmut

Re: Puzzling "exec" behavior in Windows 10

<t75ss6$16u$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19445&group=comp.lang.tcl#19445

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mssr953@gmail.com (Michael Soyka)
Newsgroups: comp.lang.tcl
Subject: Re: Puzzling "exec" behavior in Windows 10
Date: Tue, 31 May 2022 16:12:54 -0400
Organization: self
Lines: 28
Message-ID: <t75ss6$16u$1@dont-email.me>
References: <t75i39$tlf$1@dont-email.me> <t75p1k$mbi$1@dont-email.me>
<ebrc9hhpdpeqdc37bje8le33pd0m320e2m@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 31 May 2022 20:12:54 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9f46c0399580f0cfc781bb3ccee242bc";
logging-data="1246"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19oXFRIHwE+0crufVNowjze"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:4GgZeaspBxhmFsdyUNzoynk5D4Y=
In-Reply-To: <ebrc9hhpdpeqdc37bje8le33pd0m320e2m@4ax.com>
Content-Language: en-US
 by: Michael Soyka - Tue, 31 May 2022 20:12 UTC

On 05/31/2022 3:38 PM, Helmut Giese wrote:
>>
>> However, this alternative does work:
>>
>> exec -- cmd.exe /C "cd $someDir && dir"
>>
>> but I don't understand why.
>>
> Hello Mike,
> 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)

Sorry but my German is extremely limited!
Nonetheless, I'm somewhat confused by what "help cmd" displays.

However, the following does work in a cmd window without the double quotes:

cmd.exe /C cd $someDir && dir

> HTH
> Helmut
>
> PS: I got this info by typing 'help cmd' in a console window.

Re: Puzzling "exec" behavior in Windows 10

<t75tql$adt$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19446&group=comp.lang.tcl#19446

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mssr953@gmail.com (Michael Soyka)
Newsgroups: comp.lang.tcl
Subject: Re: Puzzling "exec" behavior in Windows 10
Date: Tue, 31 May 2022 16:29:09 -0400
Organization: self
Lines: 69
Message-ID: <t75tql$adt$1@dont-email.me>
References: <t75i39$tlf$1@dont-email.me> <t75p1k$mbi$1@dont-email.me>
<7NudnfumW40W7Av_nZ2dnUU7-Q_NnZ2d@giganews.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 31 May 2022 20:29:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9f46c0399580f0cfc781bb3ccee242bc";
logging-data="10685"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX186zZRk8e+P6OYvaoBl8wHY"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:JAJ53ErUKJI/o3fJ7BU11hZmah8=
In-Reply-To: <7NudnfumW40W7Av_nZ2dnUU7-Q_NnZ2d@giganews.com>
Content-Language: en-US
 by: Michael Soyka - Tue, 31 May 2022 20:29 UTC

On 05/31/2022 3:50 PM, Robert Heller wrote:
> At Tue, 31 May 2022 15:07:31 -0400 Michael Soyka <mssr953@gmail.com> 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
>>
>>
>>
>

Re: Puzzling "exec" behavior in Windows 10

<69WdncQjCMjBGwv_nZ2dnUU7-XHNnZ2d@giganews.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19448&group=comp.lang.tcl#19448

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!buffer1.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 31 May 2022 16:19:24 -0500
MIME-Version: 1.0
From: heller@deepsoft.com (Robert Heller)
Organization: Deepwoods Software
X-Newsreader: TkNews 3.0 (1.2.12)
Subject: Re: Puzzling "exec" behavior in Windows 10
In-Reply-To: <t75tql$adt$1@dont-email.me>
References: <t75i39$tlf$1@dont-email.me> <t75p1k$mbi$1@dont-email.me>?
<7NudnfumW40W7Av_nZ2dnUU7-Q_NnZ2d@giganews.com>
<t75tql$adt$1@dont-email.me>
Newsgroups: comp.lang.tcl
Content-Type: text/plain;
charset="us-ascii"
Originator: heller@sharky4.deepsoft.com
Message-ID: <69WdncQjCMjBGwv_nZ2dnUU7-XHNnZ2d@giganews.com>
Date: Tue, 31 May 2022 16:19:24 -0500
Lines: 107
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-kUTfu25oYI90gACrHC9vS46OoIHH8vP6wbmRJOfrmH5Sd82iKiWcuhY1liPiMzX8gBCC9+GwGMh0CYe!SCuec9fBBjh50hM6ZF2mcvxFfXng7/+0EGWUz6z5sVWPIj01HcfbpjkdpdipNzk2+Aci344HLsK3!9l0=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 5636
 by: Robert Heller - Tue, 31 May 2022 21:19 UTC

At Tue, 31 May 2022 16:29:09 -0400 Michael Soyka <mssr953@gmail.com> wrote:

>
> On 05/31/2022 3:50 PM, Robert Heller wrote:
> > At Tue, 31 May 2022 15:07:31 -0400 Michael Soyka <mssr953@gmail.com> 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).

The various "words" after /C are one logic operand to cmd.exe, just like the
"words" after the -c are in the case of Unix's sh. In both cases, all of the
"words" need to be collected as a single "word". This is done with quotes.

You are also misreading the exec man page. The exec command creates 1
subprocess for its first word and passes the remaining words as arguments,
possibly with special considerations for things that look like command
separaters (&&, |, ;). I guessing that since you are being upfront with
cmd.exe, you actually want something different, esp. since the cd command is a
built-in and never forks (and it makes no sense to fork it). What you want
here is a "subshell" (hense the use of "cmd.exe /C"), to handle all of your
commands. So, you need to bundle them up (with quote marks).

Basically, using "cmd.exe /C" (or "sh -c") is a special case requiring special
handling. It may or may not make sense to create a .bat (or .sh) file instead,
depending on the complexity. Then you would just run the .bat (or .sh) file:

set fp [open "temp.bat" w]
puts $fp "cd $someDir"
puts $fp "dir"
close $fp
exec cmd.exe temp.bat
file delete -force temp.bat

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

--
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
heller@deepsoft.com -- Webhosting Services


devel / comp.lang.tcl / Puzzling "exec" behavior in Windows 10

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor