tryProcess return null on failure

This commit is contained in:
2023-02-18 11:56:49 -07:00
parent 73f8b8f8c0
commit 04dc809c3e
2 changed files with 9 additions and 7 deletions

View File

@@ -675,7 +675,7 @@ class Prelude {
for (line in inputLines) {
if (line.indexOf("\n") != -1) {
handleError('newline is not allowed in the middle of a process input line: "${line.replace("\n", "\\n")}"');
return "";
return null;
}
}
}
@@ -703,7 +703,7 @@ class Prelude {
p.stdout.readall().decode().trim();
} else {
handleError('process $command $args failed:\n${p.stdout.readall().decode().trim() + p.stderr.readall().decode().trim();}');
return "";
return null;
}
} else {
// The haxe extern for FileIO.readline() says it's a string, but it's not, it's bytes!
@@ -735,7 +735,7 @@ class Prelude {
p.stdout.readAll().toString().trim();
} else {
handleError('process $command $args failed:\n${p.stdout.readAll().toString().trim() + p.stderr.readAll().toString().trim()}');
return "";
return null;
}
} else
#end
@@ -750,7 +750,7 @@ class Prelude {
return output;
} catch (e) {
handleError('process $command $args failed: $e');
return "";
return null;
}
#elseif hxnodejs
var p = if (inputLines != null) {
@@ -769,12 +769,12 @@ class Prelude {
var error:Buffer = p.stderr;
if (error == null) error = Buffer.alloc(0);
handleError('process $command $args failed:\n${output.toString() + error.toString()}');
return "";
return null;
}
return output;
#else
handleError("Can't run a subprocess on this target.");
return "";
return null;
#end
}

View File

@@ -406,7 +406,9 @@ class BasicTestCase extends Test {
#if (sys || hxnodejs)
function testTryProcess() {
Assert.equals("", Prelude.tryProcess("_ThisCoMMaNDWillSURElYFaiLLLLLL", [], error->{return;}));
// tryProcess returns null on failure:
Assert.equals(null, Prelude.tryProcess("_ThisCoMMaNDWillSURElYFaiLLLLLL", [], error->{return;}));
// tryProcess returns output on success:
Assert.equals("4.2.5", Prelude.tryProcess("haxe", ["--version"], error->{throw error;}));
}
#end