Comments (12)
The error message isn't helpful because Windows is giving us conflicting information.
From the docs for CreateProcess:
If the function fails, the return value is zero. To get extended error information, call GetLastError.
In your case, CreateProcess
returns zero, but GetLastError
thinks "the operation completed successfully". I have not been able to track down what could cause this to happen.
from childprocess.
Yeah, I figured it was something weird like that.
In my case though I'm curious about why the command is failing at all. As I said, Open3 has no problem spawning the exact same process, so why is ChildProcess failing? Odd...
from childprocess.
Same issue. Windows 8.1 and Ruby 2.0.0-p247. Any workaround is available?
from childprocess.
What seems to work for me is adding "cmd.exe /c" in front of it. I'm guessing this is because you are actually calling a .bat file and according to the docs:
To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the following arguments: /c plus the name of the batch file.
Now lpApplicationName is set to NULL here: https://github.com/jarib/childprocess/blob/master/lib/childprocess/windows/process_builder.rb#L75
However it seems that just adding it to lpCommandLine does the same trick.
from childprocess.
@rarenerd Indeed - CreateProcess won't execute batch files directly. Both of these seem to solve the problem:
ChildProcess.build("ruby", "-S", "bundle")
ChildProcess.build("cmd.exe", "/c", "bundle")
from childprocess.
So is there any way that ChildProcess
could be made to detect batch files and automatically run them using an interpreter? Would that be desirable behavior? If not, ChildProcess's inability to run batch files directly on Windows is probably something that should be documented. Either way, I'm not sure this issue should be closed just yet.
from childprocess.
I'm very reluctant to customize behaviour depending on what type of file is being executed. This is also consistent with what we already do on Unix - if you want to have your command interpreted, you need to explicitly run the shell yourself
ChildProcess.build("bash", "-c", "echo *")
# vs.
ChildProcess.build("echo", "*")
This is deliberately in contrast to Kernel#exec
's default behaviour.
I'd be happy to accept a pull requests that documents the Windows workaround though.
from childprocess.
I'm confused. If this is consistent with how Unix does things, then why is the exact same command that works on Unix failing on Windows? Is it just because Windows ignores the hash bang at the start of the file whereas Unix uses that information?
If that's the case, couldn't ChildProcess
somehow emulate that behavior to bring Windows more in line with the way Unix does things? I'd really prefer to avoid having to write a special case Windows if I can help it.
from childprocess.
I didn't claim it is consistent with "how Unix does things", but that ChildProcess is consistent in the decision not to execute commands through a command-line interpreter on either platform.
Even if you consider that moot, I can't imagine what a satisfactory heuristic to detect when to execute in cmd.exe
would look like – which I think indicates it's better to leave the decision to the user.
If you know you always want cmd.exe
on Windows, it's fairly simple to do:
def create_process(*cmd)
cmd.unshift("cmd.exe", "/c") if ChildProcess.windows?
ChildProcess.build(*cmd)
end
from childprocess.
Hmm, yeah I think I see what you're saying. Obviously you don't want to interpret any shell commands passed to ChildProcess.build
, you just want to execute the batch file using the desired arguments.
Is there a reason though that we can't just use the hash-bang in the first line of a file to determine whether or not to invoke an interpreter? That's what Unix does, right? Although, usually the paths to the interpreters used in hash-bang lines are very Unix-specific, so maybe that wouldn't work...
from childprocess.
Hold on a second! How does Open3
resolve this problem? As shown in the example in my original post, Open3.popen3
works fine, and I'm pretty sure Open3
doesn't invoke cmd.exe
for every command I run with it. Open3
also has the same behavior as ChildProcess
in that it passes the arguments listed in the method call directly to the spawned process without interpreting them as shell commands. So what are they doing that we've missed?
from childprocess.
Open3 uses Process.spawn
under the hood. You'll have to dig through the C source to figure out how it decides to invoke the shell.
from childprocess.
Related Issues (20)
- Redirect to IO.pipe on Windows causes inability to start a process HOT 6
- Security Question: Is there a reason childprocess is released as an unsigned gem? HOT 2
- FFI is a required pre-requisite HOT 4
- Pipe i/o example in documentation is incorrect HOT 2
- Erro ao rodar o comando rspec -fd HOT 1
- childprocess kills detached windows process on exit HOT 4
- FFI is a required pre-requisite for Windows or posix_spawn support in the ChildProcess gem. HOT 1
- A backend based on Process.spawn HOT 12
- Ruby 3.0 support HOT 10
- code hanging attempting to @thread.join HOT 1
- Should work for the M1 chip, but needs to be mapped or smth
- `host_cpu` changes between Ruby 2.7.2 and 2.7.3 HOT 2
- FFI installes but rake test get error HOT 4
- cannot load such file -- ffi (LoadError) HOT 2
- Use with StringIO HOT 1
- posix_spawn is not yet supported on aarch64-linux (aarch64-linux), HOT 2
- posix_spawn is not yet supported on sparc-solaris (sparc-solaris2.11) HOT 1
- I happen to be having this error after even having all both ruby, gem, and even chocolatey handy HOT 2
- Test suite is going to be broken with Ruby 3.3 HOT 1
- differences between macos and linux HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from childprocess.