T
Tobias Reif
Hi
I have to deal with the annoying shell of Windows.
Some stuff works OK via
SHELL =
if CONFIG["arch"] =~ /win/
# more stuff based on www.ruby-talk.org/9739, thanks Phil
... but I can't get the output of commands which include backslashes.
Often they can be replaced with forward slashes, eg when a file path
is passed as arg to a program.
But if the strings which are passed directly to the shell contain
backslashes, eg when the program itself is called via a path, then
there is no output.
# those work: (don't contain backslashes)
puts `command.com /c ver`
# Windows Millennium [Version 4.90.3000]
puts `command.com /c ruby -v`
# ruby 1.6.5 (2001-09-19) [i386-cygwin]
# this works on the commandline:
# \for-programs\use\tidy\tidy.exe -v
# HTML Tidy for Windows released on 1st February 2003
# this doesn't work (as expected):
# /for-programs/use/tidy/tidy.exe -v
# Befehl oder Dateiname nicht gefunden.
# [command not found]
# these don't work (nothing printed)
# how to get this to work?
puts `command.com /c \for-programs\use\tidy\tidy.exe -v`
puts `command.com /c \\for-programs\\use\\tidy\\tidy.exe -v`
# also doesn't work (as expected):
puts `command.com /c /for-programs/use/tidy/tidy.exe -v`
# Befehl oder Dateiname nicht gefunden.
# [command not found]
I tried various stuff
def shell command
#full_command = SHELL+' '+command.gsub(/\\/,'\&\&')
# or
# full_command = SHELL+' '+command.dump
`#{full_command}`
end
... but nothing works so far. No error message, but also no output.
How to escape a backslash in order to pass a single backslash to the
shell?
I appreciate any solution, even dirty hacks and quirky workarounds
Tobi
I have to deal with the annoying shell of Windows.
Some stuff works OK via
SHELL =
if CONFIG["arch"] =~ /win/
# more stuff based on www.ruby-talk.org/9739, thanks Phil
... but I can't get the output of commands which include backslashes.
Often they can be replaced with forward slashes, eg when a file path
is passed as arg to a program.
But if the strings which are passed directly to the shell contain
backslashes, eg when the program itself is called via a path, then
there is no output.
# those work: (don't contain backslashes)
puts `command.com /c ver`
# Windows Millennium [Version 4.90.3000]
puts `command.com /c ruby -v`
# ruby 1.6.5 (2001-09-19) [i386-cygwin]
# this works on the commandline:
# \for-programs\use\tidy\tidy.exe -v
# HTML Tidy for Windows released on 1st February 2003
# this doesn't work (as expected):
# /for-programs/use/tidy/tidy.exe -v
# Befehl oder Dateiname nicht gefunden.
# [command not found]
# these don't work (nothing printed)
# how to get this to work?
puts `command.com /c \for-programs\use\tidy\tidy.exe -v`
puts `command.com /c \\for-programs\\use\\tidy\\tidy.exe -v`
# also doesn't work (as expected):
puts `command.com /c /for-programs/use/tidy/tidy.exe -v`
# Befehl oder Dateiname nicht gefunden.
# [command not found]
I tried various stuff
def shell command
#full_command = SHELL+' '+command.gsub(/\\/,'\&\&')
# or
# full_command = SHELL+' '+command.dump
`#{full_command}`
end
... but nothing works so far. No error message, but also no output.
How to escape a backslash in order to pass a single backslash to the
shell?
I appreciate any solution, even dirty hacks and quirky workarounds
Tobi