os: add `raw_execute` on Windows (#14363)

Larpon 2022-05-11 15:56:03 +02:00 committed by Jef Roosens
parent 66e61d771e
commit d8531717d1
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 19 additions and 0 deletions

View File

@ -367,6 +367,15 @@ pub fn execute(cmd string) Result {
}
}
// raw_execute does the same as `execute` on Unix platforms.
// On Windows raw_execute starts the specified command, waits for it to complete, and returns its output.
// It's marked as `unsafe` to help emphasize the problems that may arise by allowing, for example,
// user provided escape sequences.
[unsafe]
pub fn raw_execute(cmd string) Result {
return execute(cmd)
}
[manualfree]
pub fn (mut c Command) start() ? {
pcmd := c.path + ' 2>&1'

View File

@ -293,6 +293,8 @@ pub fn get_error_msg(code int) string {
}
// execute starts the specified command, waits for it to complete, and returns its output.
// In opposition to `raw_execute` this function will safeguard against content that is known to cause
// a lot of problems when executing shell commands on Windows.
pub fn execute(cmd string) Result {
if cmd.contains(';') || cmd.contains('&&') || cmd.contains('||') || cmd.contains('\n') {
return Result{
@ -300,6 +302,14 @@ pub fn execute(cmd string) Result {
output: ';, &&, || and \\n are not allowed in shell commands'
}
}
return unsafe { raw_execute(cmd) }
}
// raw_execute starts the specified command, waits for it to complete, and returns its output.
// It's marked as `unsafe` to help emphasize the problems that may arise by allowing, for example,
// user provided escape sequences.
[unsafe]
pub fn raw_execute(cmd string) Result {
mut child_stdin := &u32(0)
mut child_stdout_read := &u32(0)
mut child_stdout_write := &u32(0)