Skip to content

Commit 8ca4cd8

Browse files
author
Daniel Kroening
committed
fix a run() variant on non-Windows OSs
The variant now supports input and stderr redirects. Furthermore, it uses the 'what' parameter to determine the executable, instead of argv[0], which is consistent with the other variant and the implementation for Windows.
1 parent 18328db commit 8ca4cd8

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/util/run.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,25 @@ int run(
493493
#else
494494
std::string command;
495495

496+
bool first = true;
497+
498+
// note we use 'what' instead of 'argv[0]' as the name of the executable
496499
for(const auto &arg : argv)
497-
command += " " + shell_quote(arg);
500+
{
501+
if(first) // this is argv[0]
502+
{
503+
command += shell_quote(what);
504+
first = false;
505+
}
506+
else
507+
command += " " + shell_quote(arg);
508+
}
509+
510+
if(!std_input.empty())
511+
command += " < " + shell_quote(std_input);
512+
513+
if(!std_error.empty())
514+
command += " 2> " + shell_quote(std_error);
498515

499516
FILE *stream=popen(command.c_str(), "r");
500517

0 commit comments

Comments
 (0)