#Can't seem to set stdin in std.ChildProcess

1 messages · Page 1 of 1 (latest)

fiery bramble
#

is it just me or

            var diff_file = std.fs.cwd().openFile(buffer, .{}) catch unreachable;
            defer diff_file.close();

            var process = std.ChildProcess.init(
                &[_][]const u8{"patch"}, allocator
            );

            process.stdin = diff_file;

            try process.spawn();

            std.debug.print("{any}\n", .{process});
            switch (try process.wait()) {
                .Exited => {},
                else => {
                    std.debug.print("Something failed!\nChange directory into quickjs and run this command: patch < {s}\n", .{buffer});
                }
            }

is not doing anything?

#

I have also tried to set stdin_behavior to Pipe, didn't help, the command is just stuck

#

there is something I can try

#

seems like zig setups a pipe, so I can read the diff file and write it to the pipe

#

doesn't seem to do anything either

short ridge
#

there is no dup behavior in that enum...

fiery bramble
#

I started to read the source code

#

figured it out

short ridge
#

what do you mean

fiery bramble
#

if behavior is Pipe, it setups pipe

#
if (self.stdin_behavior == StdIo.Pipe) {
            self.stdin = File{ .handle = stdin_pipe[1] };
#

then stdin is being set

short ridge
#

ah you're correct

fiery bramble
#

so then, I did writeAll and still nothing

short ridge
#

must have missed that

fiery bramble
#

maybe call sync as well?

#

that did the trick

#

now I can't get it to unstuck heh, closing the pipe does nothing

#

I'll figure that out on my own, for now. I have figured out how to correctly send Stdin

short ridge
#

sounds like you wrote to the stdin and you deadlock because you're not reading from its stdout at the same time

fiery bramble
#

I could read from stdout and search for done

#

and just found another function, which could help me

#

anyways, the issue is resolved, still thanks