Unix C 代码 cp in system()
我有一个C代码.. 我有以下 UNIX 代码:
l_iRet = system( "/bin/cp -p g_acOutputLogName g_acOutPutFilePath");
当我运行生成的二进制文件时..我收到以下错误:
cp: cannot access g_acOutputLogName
任何人都可以帮助我吗?
I have a C code..
i which I have following code for UNIX:
l_iRet = system( "/bin/cp -p g_acOutputLogName g_acOutPutFilePath");
when I am running the binary generated..I am getting the following error:
cp: cannot access g_acOutputLogName
Can any one help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,您应该更喜欢 exec 函数系列而不是系统函数。系统函数将命令传递给 shell,这意味着您需要担心命令注入和意外的参数扩展。使用exec调用子进程的方法如下:
You should generally prefer the exec family of functions over the system function. The system function passes the command to the shell which means that you need to worry about command injection and accidental parameter expansion. The way to call a subprocess using exec is as follows:
据推测,
g_acOutputLogName
和g_acOutPutFilePath
是程序中的char[]
(或char*
)变量,而不是实际的变量涉及的路径。您需要使用其中存储的值,而不是变量名称,例如:
Presumably
g_acOutputLogName
andg_acOutPutFilePath
arechar[]
(orchar*
) variables in your program, rather than the actual paths involved.You need to use the values stored therein, rather than the variable names, for example: