Skip to content
Tcl Source Code View Ticket
Login

View Ticket

windows: exec doesn't find symlink without full path

Closed / Invalid914108ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 22 years ago
Descriptionplain2004-03-11 13:13:33
OS: Windows/Cygwin

$ tclsh
% exec gzip --version
gzip 1.3.5

% exec gunzip --version
couldn't execute "gunzip": no such file or directory

% exec /usr/bin/gunzip --version
couldn't execute "D:\cygwin\bin\gunzip": invalid argument

% exec /usr/bin/gunzip.exe --version
gzip 1.3.5

$ ls -l /usr/bin/gunzip
lrwxrwxrwx    1 Samson   Users          19 Nov 27 15:20
/usr/bin/gunzip -> gzip.exe

So, gunzip is a link. Fine, why not.
But why exec is not able to consider links
when searching for the target in its known
directories?

Does it work on a pure Unix box?

Please amend the doc to state that.
(I didn't see anything in 8.4.5)
vincentdarley Ticket [914108ffff]: 1 change [History diff]2004-03-22 19:31:32
vincentdarleyplain2004-03-22 19:31:33
Logged In: YES 
user_id=32170

I have no knowledge of cygwin, so re-assigning.
davygrvyplain2004-06-03 13:53:02
Logged In: YES 
user_id=7549

symlinks from bash aren't file system entities with cygwin.

To see, open gunzip.exe into notepad and you get:
!<symlink>gzip.exe 

that text file doesn't have a valid PE header, therefore it 
connot be run as an executable because it isn't one.

If it was up to me, I'd mark this bug report invalid and close it.
davygrvyplain2004-06-03 15:15:16
Logged In: YES 
user_id=7549

To put it another way, there aren't any Win32 functions to 
decode a cygwin symlink text file.
p_samsonplain2004-06-03 19:43:10
Logged In: YES 
user_id=994002

David,
Thanks for pointing how cygwin symlink are made.
I understand that  they are not real exe.

But I would not consider this report invalid and
closed, unless you can explain why:
  exec /usr/bin/gunzip.exe
works but
  exec /usr/bin/gunzip
  exec gunzip
do not.
dgpplain2004-06-03 20:23:33
Logged In: YES 
user_id=80530


Has the submitter tried:

eval exec [auto_execok gunzip]

?

That's the more reliable, recommended
construct.
hobbsplain2004-06-03 23:27:29
Logged In: YES 
user_id=72656

auto_execok is the way to go:

(Tcl) 49 % auto_execok gunzip
C:/cygwin/bin/gunzip.EXE

In any case, the reason that only the full path works is
because that is the only valid exe from Windows point of
view.  Cygwin does lots of bizarre pseudo-Windows stuff that
just isn't valid from the real Windows point of view.
dgpplain2004-06-03 23:42:37
Logged In: YES 
user_id=80530


then just watch out for
Bug 954263.  It's fixed now,
but will cause trouble if
you're using Tcl 8.5a1
p_samsonplain2004-06-04 21:45:39
Logged In: YES 
user_id=994002

OK for auto_execok if it helps to find the path to the
executable to gunzip. But I still find a little strange that
%exec gzip works without any help.
Both files are located at the same place:
D:\cygwin\bin\gzip.exe
D:\cygwin\bin\gunzip.exe
The only difference is that the latter doesn't have a real
executable struture, but [auto_execok gunzip] neither.

Now, another point of frustration:
% exec [auto_execok gunzip] x.gz
gzip: x.gz already has .gz suffix -- unchanged

gzip.exe is executed as expected but it checks if it
has been so with the application name 'gun*' to
know if decompression must be exerciced.

If you look at tcl8.4.1\win\tclWinPipe.c:
    if ((*tclWinProcs->createProcessProc)(NULL, 
    (TCHAR *) Tcl_DStringValue(&cmdLine), NULL, NULL, TRUE, 
    (DWORD) createFlags, NULL, NULL, &startInfo, &procInfo)
== 0) {

The first argument is lpApplicationName. If it contains
'gunzip' then gzip.exe knows it must decompress.
With NULL, the application name is taken from the
second argument, which contains 'gzip', so compression
is selected.

Any chances to have the application name included
in the process creation call?
davygrvyplain2004-06-05 02:50:46
Logged In: YES 
user_id=7549

But if you look earlier in TclpCreateProcess, you'll see that 
ApplicationType() reads the PE header of gunzip.exe and find 
that it is invalid as an executable.
nobodyplain2004-06-05 12:20:04
Logged In: NO 

Even the command shell doesn't know what to do with it:

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\cygwin\bin>gunzip

C:\cygwin\bin>
p_samsonplain2004-06-05 13:51:31
Logged In: YES 
user_id=994002

My mistake. Remember that I run a Cygwin version, not a
Windows version. I shouldn't have mention tclWinPipe.c,
but tclUnixPipe.c. In TclpCreateProcess, the call is to
 execvp(newArgv[0], newArgv);
execvp is in winsup\cygwin\exec.cc. I didn't find anything
obvious in a few minutes, for this comment.

Comparison should be done with a bash shell, not a cmd.exe:
$ gunzip --version
gunzip 1.3.5
nobodyplain2004-06-05 21:15:52
Logged In: NO 

Then you should send a bug report to the cygwin folks as 
execvp() is not in the Tcl code.
p_samsonplain2004-06-06 15:48:45
Logged In: YES 
user_id=994002

Well, I had to browse deeper in code, and strace.exe the runs
to know more.
First let's correct some of my wrong previous assertions:
- Forget tclUnixPipe.c and execvp(). For the cygwin package
tclWinPipe.c is used.
- Forget what I wrote about lpApplicationName. Even directly
from bash, a CreateProcess() is called with
lpApplicationName = "C:\cygwin\bin\gzip.exe"
lpCommandLine="C:\cygwin\bin\gzip.exe /tmp/some.gz"

Now, what I think is the explanation:
bash uses spawn.cc. CreateProcess() is called in spawn_guts()
of this source, with extra information in
lpStartupInfo.lpReserved2 (which should be NULL for a
MSC Runtime exe).
This info will provide the argv for the child process, but
with the replacement of argv[0]:
 newargv.replace0_maybe (prog_arg);
That's how gzip.exe gets its arg[0] as "/bin/gunzip.exe".

Note: the cygwin starter also supports lpReserved2 as NULL,
but then all this wizardry for arg[0] is missing.

I guess there is no way for TCL to satisfy these cygwin
internals, so I'm on my own to replace every "gunzip" with
"gzip -d" in the tcl-based open source products I use.
And for any !<symlink> form of exe as well.

Thanks anyway to all for your comments and assistance.
Log in (anonymous is fine) to add a comment.