Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests involving [exec program >> file] fail on MSYS2/MinGW-w64 #59

Closed
dbohdan opened this issue Aug 29, 2016 · 6 comments
Closed

Tests involving [exec program >> file] fail on MSYS2/MinGW-w64 #59

dbohdan opened this issue Aug 29, 2016 · 6 comments

Comments

@dbohdan
Copy link
Contributor

dbohdan commented Aug 29, 2016

This is a separate issue for the bug I found in #57.

Each of the failed tests involves [exec] appending the output of a command to a file. E.g. (this is the MSYS2 shell),

$ ./jimsh.exe -e 'exec echo "First line" >> new.file' && cat new.file
/usr/bin/echo: write error: Bad file descriptor

However, the > redirect works:

$ ./jimsh.exe -e 'exec echo "First line" > new.file' && cat new.file

First line

@dbohdan dbohdan changed the title Appending the output of a command to a file with [exec] fails on MinGW-w64 builds Appending the output of a program to a file with [exec] fails on MinGW-w64 builds Aug 29, 2016
@msteveb
Copy link
Owner

msteveb commented Aug 29, 2016

I don't have the environment to be able to reproduce this error, so hopefully you or someone else can resolve it.

@dbohdan
Copy link
Contributor Author

dbohdan commented Aug 29, 2016

Right. I made this as a bookmark for myself and in hope someone else might notice.

@dbohdan
Copy link
Contributor Author

dbohdan commented Aug 29, 2016

The problem doesn't manifest when the Jim Tcl binary built with MinGW-w64 (jimsh.exe) executes plain Windows console programs like cmd.exe:

C:\msys32\home\User\jimtcl>jimsh.exe -e "exec cmd.exe /c echo hi >> hi.txt"


C:\msys32\home\User\jimtcl>type hi.txt
hi

This suggests the bug may be the result of a normal Windows binary (jimsh.exe) interacting with ones built specifically for the MSYS2 environment (echo.exe), meaning the scope of the bug is narrower than it seemed from the start. One thing to check now is if it is possible to reproduce it with programs other than Jim Tcl starting MSYS2 binaries, i.e., if the bug is specific to Jim Tcl.

Edit: Tcl 8.6.4 and busybox-w32 redirect the output of MSYS2 executables normally, meaning the source code to mainline Tcl's [exec] is worth comparing to Jim's.

@dbohdan dbohdan changed the title Appending the output of a program to a file with [exec] fails on MinGW-w64 builds Tests involving [exec program >> file] fail on MSYS2/MinGW-w64 Aug 29, 2016
@msteveb
Copy link
Owner

msteveb commented Aug 29, 2016

The windows code in jim-exec.c is derived in large part from Tcl 8.6
One of the few differences I notice in the create flags that are passed to CreateProcess(). Perhaps Jim needs DETACHED_PROCESS.

@msteveb
Copy link
Owner

msteveb commented Aug 29, 2016

I also notice that Tcl doesn't use FILE_APPEND_DATA. Instead after opening, it seeks to the end of the file with:

SetFilePointer(handle, 0, NULL, FILE_END);

@dbohdan
Copy link
Contributor Author

dbohdan commented Aug 29, 2016

Great find! Replacing FILE_APPEND_DATA with a call to SetFilePointer fixes all the append-related tests. (DETACHED_PROCESS didn't.) Now only 12.1 remains. I would simply add a unix constraint to it.

PR: #60.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants