I have the following code, which creates children process. Children process is a shell script on unix platform, which prints two lines to stdout. Parent process reads that output via the pipe:
char *shell_command = "cd /home/user; for infofile in *.info ; do grep -q 'PID: 10631$' ${infofile} ; if [ $? = 0 ]; then grep 'Trace File:' ${infofile} | awk '{ print $3 }' ; grep 'Trace Signal:' ${infofile} | awk '{ print $3 }' ; fi; done";
char *buf = new char[255];
cout<<"1"<<endl;
FILE *cmd_ptr=popen(shell_command, "r");
if (cmd_ptr != (FILE *) NULL){
fgets(buf, 254, cmd_ptr);
if ((feof(cmd_ptr) || (strlen(buf) == 0))){
exit 1;
}
cout<<"2"<<endl;
}
After performing that code I expect to get in stdout digits "1" and "2", but the following output is appeared:
1
Not a terminal
2
What means "Not a terminal" and which point in the code generates this phrase? Is it is from popen() function or is it from that children shell script?
Moreover, I expect the buffer contain the line:
/xtz/sysp/SysPilot/instances/tst/err/xtz_11.0-0.neis_0001
But actually it is like the following:
<thrash>/xtz/sysp/SysPilot/instances/tst/err/xtz_11.0-0.neis_0001
where <thrash> is 97 symbols. Why that thrash was appeared in the beginning of the buffer? If you are interesting in that thrash, below are HEX codes of that 97 symbols. It is interesting that the first and the last thrash-symbols have code 0D (13):
0D 1B 5B 33 67 0D 20 20 20 20 20 20 20 20 1B 48 20 20 20 20
20 20 20 20 1B 48 20 20 20 20 20 20 20 20 1B 48 20 20 20 20
20 20 20 20 1B 48 20 20 20 20 20 20 20 20 1B 48 20 20 20 20
20 20 20 20 1B 48 20 20 20 20 20 20 20 20 1B 48 20 20 20 20
20 20 20 20 1B 48 20 20 20 20 20 20 20 20 1B 48 0D
thanks for any your suggestions.