我正在使用一些管道和叉子來執行命令,如Execlp調用沒有TTY的bash
cat file.tar.gz | myprogram -c 「焦油-zvt」 -i 「remoteMachineIp」
但如果我不
myprogram -c 「慶典」 -i 「remoteMachineIp」
bash的是好的,但沒有終端。 沒有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 如果我叫SSH用戶@機器「慶典」在bash自帶的問題,而是突出部分SSH用戶@機器其好的
我怎樣才能用tty調用bash?
感謝
我正在使用bash -c,因爲項目需要它,所有在套接字中調用的程序都將使用bash。有沒有辦法使用管道和fork與tty? – Lefsler
即使它是'bash'腳本(與普通的'sh'腳本相反),你仍然可以按照啓動東西的標準方式啓動它'sh -c'。如果它是一個Python或Perl或lua腳本或其他任何東西,它就可以工作。 –
Celada
「用管道和叉子與tty」?那麼,你的命令的stdio將是一個管道,或者它將是tty。它不能兼而有之。 – Celada