Issue #16688 has been updated by dsisnero (Dominic Sisneros).


I think what would be useful is when interpolating Path like objects (to_path) that the path objects are shell escaped or cmd escaped when used with system() or other cmd running objects.  There are always errors on windows with directories or files with spaces.  I like how Julia language deals with these in shell commands- they automatically escape the strings and expand the arrays but if we can't do that, I do agree with this proposal.

----------------------------------------
Feature #16688: Allow #to_path object as argument to system()
https://bugs.ruby-lang.org/issues/16688#change-84964

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
* Priority: Normal
----------------------------------------
I often work with Pathname objects, but when passing them to a system command I find it a bit tedious that they have to be explicitly converted to a String.

```ruby
file = BASE + "config.json"
system(@cmd, file)      #=> TypeError (no implicit conversion of Pathname into String)
system(@cmd, file.to_s) #=> works
```

I propose that the system/exec/spawn family of methods should try to convert their arguments using `to_path`, if `to_str` fails. I believe it makes perfect sense, since commandline arguments are so often pathnames.

This includes in/out redirection. `system("ls", out: Pathname.new("file"))` should be valid.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>