作者florenceL (佛罗伦斯)
看板C_and_CPP
标题[问题] cat:no such file or directory
时间Tue Nov 10 20:52:21 2015
我要在code中执行cat ooo.html
所以我在code中写execlp("/bin/cat","cat","ooo.html",NULL)
执行完有跑出正确的结果
但是我如果用pch1=strtok(readcmd," ");pch2=strtok(NULL," ");
readcmd="cat ooo.html"(readcmd是从键盘输入)
我把pch2印出来也是ooo.html
然後我再写execlp("/bin/cat","cat",pch2,NULL)
执行的结果就会变成如下错误讯息
cat: ooo.html
no such file or directory
我用strcmp(pch2,"ooo.html")回传的结果是>0不是等於0
表示pch2不是"ooo.html"
这样是不是表示strtok加一些字元到pch2?
我要对pch2做甚麽处理
才能使用execlp("/bin/cat","cat",pch2,NULL)
而不会出现错误讯息?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.115.53.27
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1447159958.A.7CA.html
※ 编辑: florenceL (140.115.53.27), 11/10/2015 20:56:00
※ 编辑: florenceL (140.115.53.27), 11/10/2015 20:58:31
※ 编辑: florenceL (140.115.53.27), 11/10/2015 21:04:01
1F:→ florenceL: 找到原因了是strtok会多塞空字元 11/10 21:52