2 * Copyright 2005-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include "external_commands.h"
17 static FILE* sInput
= fdopen(3, "r");
25 static FILE* sOutput
= fdopen(4, "w");
31 FSShell::get_external_command(char* buffer
, int size
)
33 // get the input stream
34 FILE* in
= get_input();
36 fprintf(stderr
, "Error: Failed to open command input: %s\n",
42 // read a command line
43 if (fgets(buffer
, size
, in
) != NULL
)
46 // when interrupted, try again
54 FSShell::reply_to_external_command(int result
)
56 // get the output stream
57 FILE* out
= get_output();
59 fprintf(stderr
, "Error: Failed to open command output: %s\n",
64 if (fprintf(out
, "%d\n", result
) < 0 || fflush(out
) == EOF
) {
65 fprintf(stderr
, "Error: Failed to write command reply to output reply: "
66 "%s\n", strerror(errno
));
72 FSShell::external_command_cleanup()
74 // The file will be closed automatically when the team exits.