1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: add raw_execute on Windows (#14363)

This commit is contained in:
Larpon 2022-05-11 15:56:03 +02:00 committed by GitHub
parent 26b81d68b5
commit 34a252ef84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)