os: add `raw_execute` on Windows (#14363)
							parent
							
								
									66e61d771e
								
							
						
					
					
						commit
						d8531717d1
					
				|  | @ -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' | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue