[英]Is it possible to include a shell script in a C program
I've been successful in writing a C program that copies files from one directory to another and I'm trying to write one that copies directories and sub-directories to another directory. 我已经成功编写了将文件从一个目录复制到另一个目录的C程序,并且我正在尝试编写一个将目录和子目录复制到另一个目录的程序。
I've equally been able to write a shell script that copies directories and sub-directories from one location to another. 我同样能够编写一个Shell脚本,将目录和子目录从一个位置复制到另一个位置。
So, I wish to ask if it is possible to include a shell script into a C program so I won't have to spend time writing another C program to copy directories and sub-directories. 因此,我想问一问是否可以在C程序中包含shell脚本,这样我就不必花时间编写另一个C程序来复制目录和子目录。
Yes its definately possible to call shell scripts or other scripts/executables from C using system(..)
function call. 是的,绝对可以使用system(..)
函数调用从C调用Shell脚本或其他脚本/可执行文件。 Check system(3) . 检查系统(3) 。
For the given task of copying directories and subdirectories you can easily code it in C using opendir()
, readdir()
, and other API's. 对于复制目录和子目录的给定任务,您可以使用opendir()
, readdir()
和其他API在C语言中轻松对其进行编码。
Check Copy directory recursively in pure C on Linux/UNIX for more details 有关更多详细信息,请在Linux / UNIX上以纯C递归检查复制目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.