我有一个父进程,它从子进程读取输出,并在必要时将输入写入子进程。子进程到达一行java代码(不是我的代码,不能改变),它接受一个整数作为输入。我无法通过write()调用来发送整数和换行符(以模拟按下)。我已经尝试了在其他线程中找到的许多建议无济于事。有办法吗?
write(PARENT_WRITE_FD, "1\n", 2); //Log file says ^@1 entered
int choice = 1;
write(PARENT_WRITE_FD, &choice, 1);
write(PARENT_WRITE_FD, "\n", 1); //Loops back around as if I just pushed enter
char choice = 1;
write(PARENT_WRITE_FD, &choice, 1);
write(PARENT_WRITE_FD, "\n", 1); //Loops back around as if I just pushed enter
char choice[2] = {0x31, 0x0D}; // 1 and CR
write(PARENT_WRITE_FD, &choice, 2); //Incorrect choice:726
char choice = "\001";
write(PARENT_WRITE_FD, &choice, 1);
write(PARENT_WRITE_FD, "\n", 1); //Forget the outcome, but didn't work
解析输入的Java代码:
String[] enteredChoice = enteredChoiceStr.split(",");
for ( String indexStr : enteredChoice ) {
int index = Integer.parseInt(indexStr);
if ( index == 0 || index > totalNum ) {
isError = true;
ErrorMsg="Invalid number entered: "+indexStr+". Verify the number.";
cu.wprintln("");
cu.wprintln(ErrorMsg);