@@ -144,29 +144,20 @@ auto main(int argc, char *argv[]) -> int {
144144 return RS_RE ;
145145 }
146146 } else {
147- if (! stdinRedirect.empty ()) {
148- if (freopen (stdinRedirect.c_str (), " r" , stdin) == NULL ) {
149- perror (" freopen stdin" );
150- exit (RS_FAIL );
151- }
152- } else {
153- fclose (stdin);
147+ std::string finalStdinRedirect = stdinRedirect.empty () ? " /dev/null" : stdinRedirect;
148+ if (freopen (finalStdinRedirect.c_str (), " r" , stdin) == NULL ) {
149+ perror (" freopen stdin" );
150+ exit (RS_FAIL );
154151 }
155- if (! stdoutRedirect.empty ()) {
156- if (freopen (stdoutRedirect.c_str (), " w" , stdout) == NULL ) {
157- perror (" freopen stdout" );
158- exit (RS_FAIL );
159- }
160- } else {
161- fclose (stdout);
152+ std::string finalStdoutRedirect = stdoutRedirect.empty () ? " /dev/null" : stdoutRedirect;
153+ if (freopen (finalStdoutRedirect.c_str (), " w" , stdout) == NULL ) {
154+ perror (" freopen stdout" );
155+ exit (RS_FAIL );
162156 }
163- if (! stderrRedirect.empty ()) {
164- if (freopen (stderrRedirect.c_str (), " w" , stderr) == NULL ) {
165- perror (" freopen stderr" );
166- exit (RS_FAIL );
167- }
168- } else {
169- fclose (stderr);
157+ std::string finalStderrRedirect = stderrRedirect.empty () ? " /dev/null" : stderrRedirect;
158+ if (freopen (finalStderrRedirect.c_str (), " w" , stderr) == NULL ) {
159+ perror (" freopen stderr" );
160+ exit (RS_FAIL );
170161 }
171162
172163 rlimit memlim{}, stalim{}, timlim{};
0 commit comments