Project

General

Profile

Actions

Feature #1482

closed

Kernel.exec doesn't respect COMSPEC environment variable on Windows

Added by dolzenko (Evgeniy Dolzhenko) almost 15 years ago. Updated over 6 years ago.

Status:
Rejected
Target version:
[ruby-core:23491]

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

0001-win32.c-use-COMSPEC.patch (2.03 KB) 0001-win32.c-use-COMSPEC.patch nobu (Nobuyoshi Nakada), 10/29/2012 05:39 PM
Actions #1

Updated by ujihisa (Tatsuhiro Ujihisa) over 14 years ago

  • Status changed from Open to Assigned
  • Assignee set to usa (Usaku NAKAMURA)
Actions #2

Updated by usa (Usaku NAKAMURA) over 14 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?

Actions #3

Updated by usa (Usaku NAKAMURA) over 14 years ago

  • Priority changed from Normal to 3
  • Target version deleted (Ruby 1.8.7)
Actions #4

Updated by mame (Yusuke Endoh) about 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

Actions #5

Updated by jonforums (Jon Forums) about 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

Actions #6

Updated by nobu (Nobuyoshi Nakada) about 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 honor COMSPEC, 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

Actions #7

Updated by znz (Kazuhiro NISHIYAMA) about 14 years ago

  • Category set to core
  • Target version set to 2.0.0
Actions #8

Updated by dolzenko (Evgeniy Dolzhenko) about 14 years ago

Documentation for exec method says:

  • The standard shell means always "/bin/sh" on Unix-like systems,
  • ENV["RUBYSHELL"] or ENV["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) about 12 years ago

Hello,

Usak-san or nobu, could you tell me the status?

--
Yusuke Endoh

Updated by usa (Usaku NAKAMURA) over 11 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 usa (Usaku NAKAMURA) over 11 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) over 11 years ago

  • Assignee changed from usa (Usaku NAKAMURA) to nobu (Nobuyoshi Nakada)
  • Priority changed from 3 to Normal

Updated by mame (Yusuke Endoh) over 11 years ago

Nobu, did you?

--
Yusuke Endoh

Updated by ko1 (Koichi Sasada) about 11 years ago

  • Target version changed from 2.0.0 to 2.1.0

ping -> nobu.

Updated by nobu (Nobuyoshi Nakada) about 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) about 10 years ago

  • Target version changed from 2.1.0 to 2.2.0

Updated by mame (Yusuke Endoh) over 6 years ago

Nobu, are you still willing to reimprement the patch for this issue?

Updated by nobu (Nobuyoshi Nakada) over 6 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) over 6 years ago

  • Status changed from Assigned to Rejected

Seems Microsoft has fixed Windows.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0