mirror of
https://github.com/vlang/v.git
synced 2025-09-09 23:39:39 -04:00
parent
4dc46ed9e6
commit
c7fb7553b7
@ -339,10 +339,7 @@ pub fn mkdir(path string, params MkdirParams) ! {
|
|||||||
// execute starts the specified command, waits for it to complete, and returns its output.
|
// execute starts the specified command, waits for it to complete, and returns its output.
|
||||||
@[manualfree]
|
@[manualfree]
|
||||||
pub fn execute(cmd string) Result {
|
pub fn execute(cmd string) Result {
|
||||||
// if cmd.contains(';') || cmd.contains('&&') || cmd.contains('||') || cmd.contains('\n') {
|
pcmd := 'exec 2>&1;${cmd}'
|
||||||
// return Result{ exit_code: -1, output: ';, &&, || and \\n are not allowed in shell commands' }
|
|
||||||
// }
|
|
||||||
pcmd := if cmd.contains('2>') { cmd.clone() } else { '${cmd} 2>&1' }
|
|
||||||
defer {
|
defer {
|
||||||
unsafe { pcmd.free() }
|
unsafe { pcmd.free() }
|
||||||
}
|
}
|
||||||
|
@ -907,6 +907,16 @@ fn test_execute_with_stderr_redirection() {
|
|||||||
assert os.exists(stderr_path)
|
assert os.exists(stderr_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_execute_with_linefeeds() {
|
||||||
|
if os.user_os() == 'windows' {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
result := os.execute('true\n')
|
||||||
|
assert result.exit_code == 0
|
||||||
|
result2 := os.execute('false\n')
|
||||||
|
assert result2.exit_code == 1
|
||||||
|
}
|
||||||
|
|
||||||
fn test_command() {
|
fn test_command() {
|
||||||
if os.user_os() == 'windows' {
|
if os.user_os() == 'windows' {
|
||||||
eprintln('>>> os.Command is not implemented fully on Windows yet')
|
eprintln('>>> os.Command is not implemented fully on Windows yet')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user