-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
std.child_process: enable non-standard streams #14152
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,6 +228,16 @@ pub fn DeviceIoControl( | |
} | ||
} | ||
|
||
pub const GetHandleInformationError = error{Unexpected}; | ||
|
||
pub fn GetHandleInformation(h: HANDLE, flags: *DWORD) GetHandleInformationError!void { | ||
if (kernel32.GetHandleInformation(h, flags) == 0) { | ||
switch (kernel32.GetLastError()) { | ||
else => |err| return unexpectedError(err), | ||
} | ||
} | ||
} | ||
|
||
pub fn GetOverlappedResult(h: HANDLE, overlapped: *OVERLAPPED, wait: bool) !DWORD { | ||
var bytes: DWORD = undefined; | ||
if (kernel32.GetOverlappedResult(h, overlapped, &bytes, @boolToInt(wait)) == 0) { | ||
|
@@ -1590,6 +1600,45 @@ pub fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: [*]u16, nSize: DWORD) G | |
return rc; | ||
} | ||
|
||
// zig fmt: off | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kept these inside for #14251, but they are generally useful for other users as well short of advanced list attributes. |
||
pub const PROCESS_CREATION_FLAGS = enum(u32) { | ||
// <- gap here -> | ||
DEBUG_PROCESS = 0x0000_0001, | ||
DEBUG_ONLY_THIS_PROCESS = 0x0000_0002, | ||
CREATE_SUSPENDED = 0x0000_0004, | ||
DETACHED_PROCESS = 0x0000_0008, | ||
CREATE_NEW_CONSOLE = 0x0000_0010, | ||
NORMAL_PRIORITY_CLASS = 0x0000_0020, | ||
IDLE_PRIORITY_CLASS = 0x0000_0040, | ||
HIGH_PRIORITY_CLASS = 0x0000_0080, | ||
REALTIME_PRIORITY_CLASS = 0x0000_0100, | ||
CREATE_NEW_PROCESS_GROUP = 0x0000_0200, | ||
CREATE_UNICODE_ENVIRONMENT = 0x0000_0400, | ||
CREATE_SEPARATE_WOW_VDM = 0x0000_0800, | ||
CREATE_SHARED_WOW_VDM = 0x0000_1000, | ||
CREATE_FORCEDOS = 0x0000_2000, | ||
BELOW_NORMAL_PRIORITY_CLASS = 0x0000_4000, | ||
ABOVE_NORMAL_PRIORITY_CLASS = 0x0000_8000, | ||
INHERIT_PARENT_AFFINITY = 0x0001_0000, | ||
INHERIT_CALLER_PRIORITY = 0x0002_0000, | ||
CREATE_PROTECTED_PROCESS = 0x0004_0000, | ||
EXTENDED_STARTUPINFO_PRESENT = 0x0008_0000, | ||
PROCESS_MODE_BACKGROUND_BEGIN = 0x0010_0000, | ||
PROCESS_MODE_BACKGROUND_END = 0x0020_0000, | ||
CREATE_SECURE_PROCESS = 0x0040_0000, | ||
// <- gap here -> | ||
CREATE_BREAKAWAY_FROM_JOB = 0x0100_0000, | ||
CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x0200_0000, | ||
CREATE_DEFAULT_ERROR_MODE = 0x0400_0000, | ||
CREATE_NO_WINDOW = 0x0800_0000, | ||
PROFILE_USER = 0x1000_0000, | ||
PROFILE_KERNEL = 0x2000_0000, | ||
PROFILE_SERVER = 0x4000_0000, | ||
CREATE_IGNORE_SYSTEM_DEFAULT = 0x8000_0000, | ||
_, | ||
}; | ||
// zig fmt: on | ||
|
||
pub const CreateProcessError = error{ | ||
FileNotFound, | ||
AccessDenied, | ||
|
@@ -2940,8 +2989,6 @@ pub const COORD = extern struct { | |
Y: SHORT, | ||
}; | ||
|
||
pub const CREATE_UNICODE_ENVIRONMENT = 1024; | ||
|
||
pub const TLS_OUT_OF_INDEXES = 4294967295; | ||
pub const IMAGE_TLS_DIRECTORY = extern struct { | ||
StartAddressOfRawData: usize, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const Builder = @import("std").build.Builder; | ||
|
||
pub fn build(b: *Builder) void { | ||
const target = b.standardTargetOptions(.{}); | ||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
const child = b.addExecutable(.{ | ||
.name = "child", | ||
.root_source_file = .{ .path = "child.zig" }, | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
const parent = b.addExecutable(.{ | ||
.name = "parent", | ||
.root_source_file = .{ .path = "parent.zig" }, | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
const run_cmd = parent.run(); | ||
run_cmd.addArtifactArg(child); | ||
|
||
const test_step = b.step("test", "Test it"); | ||
test_step.dependOn(&run_cmd.step); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const std = @import("std"); | ||
const builtin = @import("builtin"); | ||
const windows = std.os.windows; | ||
pub fn main() !void { | ||
var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; | ||
defer if (general_purpose_allocator.deinit()) @panic("found memory leaks"); | ||
const gpa = general_purpose_allocator.allocator(); | ||
|
||
var it = try std.process.argsWithAllocator(gpa); | ||
defer it.deinit(); | ||
_ = it.next() orelse unreachable; // skip binary name | ||
const s_handle = it.next() orelse unreachable; | ||
var file_handle = try std.os.stringToHandle(s_handle); | ||
defer std.os.close(file_handle); | ||
|
||
// child inherited the handle, so inheritance must be enabled | ||
const is_inheritable = try std.os.isInheritable(file_handle); | ||
std.debug.assert(is_inheritable); | ||
|
||
try std.os.disableInheritance(file_handle); | ||
var file_in = std.fs.File{ .handle = file_handle }; // read side of pipe | ||
const file_in_reader = file_in.reader(); | ||
const message = try file_in_reader.readUntilDelimiterAlloc(gpa, '\x17', 20_000); | ||
defer gpa.free(message); | ||
try std.testing.expectEqualSlices(u8, message, "test123"); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont like this solution. These are very frequent operations, so it would be nice to have the sizes next to fd_t on each platform or to have a LUT. Opinions?