From b05f65986035359c6fe46ed16a43f117d81b44d5 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sun, 2 Jun 2024 09:48:44 +0800 Subject: [PATCH] print error message to std error --- tools/consolepauser/main.unix.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/consolepauser/main.unix.cpp b/tools/consolepauser/main.unix.cpp index e86c6f40..3a9790af 100644 --- a/tools/consolepauser/main.unix.cpp +++ b/tools/consolepauser/main.unix.cpp @@ -96,7 +96,7 @@ int ExecuteCommand(vector& command,bool reInp, long int &peakMemory) { int command_size; if (reInp) { if (command.size()<2) { - printf("not enough arguments1!\n"); + fprintf(stderr,"not enough arguments1!\n"); exit(-1); } freopen(unescapeSpaces(command[0]).c_str(),"r",stdin); @@ -105,7 +105,7 @@ int ExecuteCommand(vector& command,bool reInp, long int &peakMemory) { command_begin = 1; } else { if (command.size()<1) { - printf("not enough arguments2!\n"); + fprintf(stderr,"not enough arguments2!\n"); exit(-1); } path_to_command = unescapeSpaces(command[0]); @@ -126,10 +126,10 @@ int ExecuteCommand(vector& command,bool reInp, long int &peakMemory) { argv[0]=(char *)file.c_str(); int result=execv(path_to_command.c_str(),argv); if (result) { - printf("Failed to start command %s %s!\n",path_to_command.c_str(), file.c_str()); - printf("errno %d: %s\n",errno,strerror(errno)); + fprintf(stderr,"Failed to start command %s %s!\n",path_to_command.c_str(), file.c_str()); + fprintf(stderr,"errno %d: %s\n",errno,strerror(errno)); char* current_dir = getcwd(nullptr, 0); - printf("current dir: %s",current_dir); + fprintf(stderr,"current dir: %s",current_dir); free(current_dir); exit(-1); } @@ -140,7 +140,7 @@ int ExecuteCommand(vector& command,bool reInp, long int &peakMemory) { struct rusage usage; w = wait4(pid, &status, WUNTRACED | WCONTINUED, &usage); if (w==-1) { - perror("wait4 failed!"); + fprintf(stderr,"wait4 failed!"); exit(EXIT_FAILURE); } peakMemory = usage.ru_maxrss; @@ -157,9 +157,9 @@ int main(int argc, char** argv) { char* sharedMemoryId; // First make sure we aren't going to read nonexistent arrays if(argc < 4) { - printf("\n--------------------------------"); - printf("\nUsage: consolepauser <0|1> \n"); - printf("\n 1 means the STDIN is redirected by Red Panda C++; 0 means not\n"); + fprintf(stderr,"\n--------------------------------"); + fprintf(stderr,"\nUsage: consolepauser <0|1> \n"); + fprintf(stderr,"\n 1 means the STDIN is redirected by Red Panda C++; 0 means not\n"); PauseExit(EXIT_SUCCESS,false); } @@ -183,12 +183,12 @@ int main(int argc, char** argv) { int fd_shm = shm_open(sharedMemoryId,O_RDWR,S_IRWXU); if (fd_shm==-1) { //todo: handle error - printf("shm open failed %d:%s\n",errno,strerror(errno)); + fprintf(stderr,"shm open failed %d:%s\n",errno,strerror(errno)); } else { // `ftruncate` has already done in RedPandaIDE pBuf = (char*)mmap(NULL,BUF_SIZE,PROT_READ | PROT_WRITE, MAP_SHARED, fd_shm,0); if (pBuf == MAP_FAILED) { - printf("mmap failed %d:%s\n",errno,strerror(errno)); + fprintf(stderr,"mmap failed %d:%s\n",errno,strerror(errno)); pBuf = nullptr; } }