我正在使用一些管道和叉子来执行类似的命令
猫文件.tar.gz | myprogram -c "tar -zvt" -i "remoteMachineIp"
但如果我这样做
我的程序 -c “bash” -i “remoteMachineIp”
bash 没问题,但没有 tty。如果没有 tty,如果我调用 vim 命令,它会打开 vi 混乱。
我如何使用 tty 在 execlp 上调用 bash。
代码示例
if(cm->pid2==0){ //pipe and fork to send data to my execlp
close(cm->fout[0]);
dup2(cm->fout[1], 1);
execlp("bash", "bash", "-c", command.c_str(), NULL); // command is mycommand so is bash -c "bash"
}
else{
close(cm->fout[1]);
while((size=read(cm->fout[0], buffer, 2000)) > 0){
cm->message->send(buffer, size); //send the data to my program
}
//Close it and send the return code
问题是 execlp 将 bash 返回给我,但没有 tty
我如何用 tty 调用 bash?
谢谢