Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[os2/process]: Implement process_exec, and pipe_has_data #4290

Merged
merged 8 commits into from
Oct 1, 2024

Conversation

flysand7
Copy link
Contributor

@flysand7 flysand7 commented Sep 22, 2024

This PR implements a procedure to allow non-blocking reading of the stdout and stderr after starting the process using os2. This function should also be applicable to sockets, but for now there's no demand for this.

There's also a fix of errors on Windows, where win32.ERROR_BROKEN_PIPE wasn't properly converting the error into General_Error.Broken_Pipe, unlike linux and posix platforms.

The documentation for pipe() procedure has been added.

The documentation of os2/process functions has been unindented.

The following snippet demonstrates the usage of the procedure:

package main

import "core:os/os2"
import "core:fmt"

main :: proc() {
	cwd, cwd_err := os2.get_working_directory(context.allocator)
	if cwd_err != nil {
		fmt.printfln("Error getting CWD: %v", cwd_err)
		os2.exit(1)
	}
	state, stdout, stderr, err := os2.process_exec(os2.Process_Desc {
		command = []string {"odin", "check", "core/os/os2", "-vet", "-strict-style", "-vet-tabs"},
		env = os2.environ(context.allocator),
		working_dir = cwd,
	}, context.allocator)
	if err != nil {
		fmt.printfln("Error running process: %v", err)
		os2.exit(1)
	}
	fmt.printfln("----------------- STDOUT --------------------")
	fmt.printfln("%s", transmute(string) stdout)
	fmt.printfln("----------------- STDERR --------------------")
	fmt.printfln("%s", transmute(string) stderr)
	fmt.printfln("----------------- STATUS --------------------")
	fmt.printfln("%v", state)
}

@flysand7 flysand7 force-pushed the pipe-has-data branch 2 times, most recently from d439d39 to ad49ccb Compare September 23, 2024 21:12
@flysand7 flysand7 changed the title [os2]: Implement pipe_has_data procedure [os2]: Implement process_exec, process_exec_shell and pipe_has_data Sep 26, 2024
@flysand7 flysand7 marked this pull request as draft September 26, 2024 21:01
@flysand7 flysand7 changed the title [os2]: Implement process_exec, process_exec_shell and pipe_has_data [os2]: Implement process_exec, and pipe_has_data Sep 27, 2024
@flysand7 flysand7 marked this pull request as ready for review September 28, 2024 21:05
@flysand7 flysand7 changed the title [os2]: Implement process_exec, and pipe_has_data [os2/process]: Implement process_exec, and pipe_has_data Sep 28, 2024
@gingerBill gingerBill merged commit af9ae48 into odin-lang:master Oct 1, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants