Feature #1482
closedKernel.exec doesn't respect COMSPEC environment variable on Windows
Description
Here is pretty convoluted test case:
puts ENV["COMSPEC"] # => "C:\WINDOWS\system32\mycmd.exe"
File.open("1.bat", "w") { |f| f.write("time") } # create test batch file with command which waits for user input
Kernel.exec("1.bat") # now the process tree inspection shows that the "C:\WINDOWS\system32\cmd.exe" is still used to interpret 1.bat
Files
Updated by ujihisa (Tatsuhiro Ujihisa) almost 15 years ago
- Status changed from Open to Assigned
- Assignee set to usa (Usaku NAKAMURA)
Updated by usa (Usaku NAKAMURA) almost 15 years ago
- Status changed from Assigned to Feedback
This is the spec of Windows itself.
Should we change the behavior with deviating from OS standard way?
Updated by usa (Usaku NAKAMURA) almost 15 years ago
- Priority changed from Normal to 3
- Target version deleted (
Ruby 1.8.7)
Updated by mame (Yusuke Endoh) over 14 years ago
Hi, usa
Should we keep this ticket open?
I'd like to close this ticket because there is no feedback from OP.
If you'll still wait, please change the target to 1.9.x.
--
Yusuke Endoh mame@tsg.ne.jp
Updated by jonforums (Jon Forums) over 14 years ago
While I didn't report the behavior, using the code from the OP but using the TCC LE shell from http://www.jpsoft.com/tccledes.htm which has a COMSPEC of
[C:\Users\Jon\Documents]echo %COMSPEC%
C:\Program Files\JPSoft\TCCLE11\TCC.EXE
and using Process Explorer from http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx I get the same results as the OP, the TCC LE process starts a Ruby process that starts a C:\WINDOWS\system32\cmd.exe
process to interpret the bat.
I'm curious, where is it described that this behavior is the spec of Windows itself? I'm not familiar with this from the DOS or WScript/CScript scripting perspective.
OTH, if Kernel.exec
would be changed to honor COMSPEC
, would it handle spaces in the path correctly when using shells such as TCC LE?
Jon
Updated by nobu (Nobuyoshi Nakada) over 14 years ago
Hi,
At Wed, 31 Mar 2010 01:31:39 +0900,
Jon Forums wrote in [ruby-core:29147]:
I'm curious, where is it described that this behavior is the
spec of Windows itself? I'm not familiar with this from the
DOS or WScript/CScript scripting perspective.
It's depend on "the association of file extension to programs".
OTH, if
Kernel.exec
would be changed to honorCOMSPEC
, would
it handle spaces in the path correctly when using shells such
as TCC LE?
It's already done if you pass them properly.
--
Nobu Nakada
Updated by znz (Kazuhiro NISHIYAMA) over 14 years ago
- Category set to core
- Target version set to 2.0.0
Updated by dolzenko (Evgeniy Dolzhenko) over 14 years ago
Documentation for exec method says:
- The standard shell means always
"/bin/sh"
on Unix-like systems, -
ENV["RUBYSHELL"]
orENV["COMSPEC"]
on Windows NT series, and - similar.
but I still can't get it to run my customized interpreter.
When you say that it depends on "the association of file extension to programs" does
that mean association of batch files? I tried to change this to my customized
interpreter (Control Panel\Programs\Default Programs\Set Associations in Windows 7)
and Ruby is still running cmd.exe
(in the original test case).
Updated by mame (Yusuke Endoh) almost 13 years ago
Updated by usa (Usaku NAKAMURA) about 12 years ago
- Status changed from Feedback to Assigned
Now ruby recognize batch files as "programs", so they are simply passed to
CreateProcess() API.
So, current behavior is Windows' spec.
However, I suspect that this (= simply being passed to CreateProcess API) is not intended.
I'll discuss about it with nobu next week.
Updated by nobu (Nobuyoshi Nakada) about 12 years ago
Does this patch help?
Updated by usa (Usaku NAKAMURA) about 12 years ago
Can you write a test for this patch, nobu?
If so, please commit them(=this patch and the test).
Updated by usa (Usaku NAKAMURA) about 12 years ago
- Assignee changed from usa (Usaku NAKAMURA) to nobu (Nobuyoshi Nakada)
- Priority changed from 3 to Normal
Updated by mame (Yusuke Endoh) almost 12 years ago
Nobu, did you?
--
Yusuke Endoh mame@tsg.ne.jp
Updated by ko1 (Koichi Sasada) over 11 years ago
- Target version changed from 2.0.0 to 2.1.0
ping -> nobu.
Updated by nobu (Nobuyoshi Nakada) over 11 years ago
Unfortunately, I've lost my topic branch for this issue, so have to rewrite from the previous patch again.
Updated by hsbt (Hiroshi SHIBATA) almost 11 years ago
- Target version changed from 2.1.0 to 2.2.0
Updated by mame (Yusuke Endoh) about 7 years ago
Nobu, are you still willing to reimprement the patch for this issue?
Updated by nobu (Nobuyoshi Nakada) about 7 years ago
- Description updated (diff)
At least on Windows 10, doesn't CreateProcess()
honor COMSPEC
variable now?
1.rb
p $$; exec("./1.bat")
$ COMSPEC="./miniruby.exe -e 'p $$, Process.ppid, ARGV'" ./miniruby -v ./1.rb
ruby 2.5.0dev (2017-10-19 trunk 60215) [x64-mswin64_140]
1524
9148
1524
["/c", ".\\1.bat"]
Updated by nobu (Nobuyoshi Nakada) about 7 years ago
- Status changed from Assigned to Rejected
Seems Microsoft has fixed Windows.