Process.run fails if stdin is an empty string. Here is a toy program that demonstrates it:
-- cut here -- void run(string input) { werror("Input: %O\n", input); werror("Result: %O\n", Process.run( ({ "od", "-c" }), ([ "stdin": input ]) )); }
int main() { run("foo"); run(""); return 0; } -- cut here --
The for invocation (which essentiall runs "echo foo | od -c") works fine. The second crashes with an error message: "Failed to convert argument to a source".
This used to work in Pike 7.8, but fails in Pike 8.0.388 (in the version distributed with Debian 9 ("stretch")), and on the 8.0 and master branches in the Pike git repo.
The complete output I'm seeing is:
Input: "foo" Result: ([ /* 3 elements */ "exitcode": 0, "stderr": "", "stdout": "0000000 f o o\n" "0000003\n" ]) Input: "" Failed to convert argument to a source /usr/lib/pike8.0/modules/Shuffler.so:1: Shuffler.Shuffle()->add_source("") /usr/lib/pike8.0/modules/Process.pmod:617: Process.run(({"od","-c"}),mapping[1]) run-stdin.pike:4: /main()->run("") run-stdin.pike:11: /main()->main()
The issue seems to come from the code
if( res->len <= 0 ) { sub_ref(res->str); free(res); return 0; }
(i.e. a string/slice of length zero is treated as an error) in source_pikestring_make() in src/post_modules/Shuffler/a_source_pikestring.c.
Before 565043fae7f the return 0 was not there, which made the code return a freed struct instead. That change was made over 14 years ago...
So I think Shuffler had this behaviour already in 7.6. It's possible that Process.run didn't use Shuffler before 8.0 though.
Anyway, the test should probably be ( res->len < 0 ) instead.
Before 565043fae7f the return 0 was not there, which made the code return a freed struct instead. That change was made over 14 years ago...
I think it might rather be 12d9d41e83a1137846ae60ef79738e10e90825d0. I have never managed to run into Shuffler really, but one solution probably just is to close mystdin if stdin_str is the empty string?
pike-devel@lists.lysator.liu.se