我有一个用C编写的客户端-服务器应用程序。这是一个基本的应用程序,客户端向服务器发出更新请求。如果有可用更新,则会将存档文件发送给客户端。此外,客户端将其解压,并从解压的存档中运行特定的 bash 脚本。这就是总结。我将在下面介绍在客户端进行更新的 C 函数:
void executeUpdates(char *path) {
char command[100];
char *tmp;
strcpy(command, "tar xzf ");
tmp = mystrcat(command, path);
mystrcat(tmp, " -C /netnfork/updates/");
system(command); //up to this point, I created the extract command and executed it.
command[0] = '\0';
path[strlen(path) - 7] = '\0';
strcpy(command, path);
strcat(command, "/update.sh");
system(command);// up to this point, I created the command to run the update script and ran it.
}
问题如下:
问题:在第一次更新中,当我在 update.sh
脚本中放入一些简单的命令(简单是指一些命令)时,它运行良好。当我在此脚本中放入一些执行存档提取、使用 ./configure
、make
、make install
进行编译的命令时,脚本卡在具体点永远。
具体来说,在更新存档中,我需要提取并安装六个 tar.bz 存档。它对于前 5 个存档运行良好,但是当脚本到达第六个 tar.bz 安装点时,它会挂起。如果我直接从终端运行此脚本,它运行良好,没有任何问题。
问题:有人对解决这个问题有一些想法吗?
注意如果您需要更具体的细节或脚本内容,请告诉我。
注意B1。我以 root 身份运行更新 C 程序。
最佳答案
如果我理解正确的话,你的 bash 脚本在某种程度上运行良好,然后出现故障。可能某些进程显示错误消息,但您没有阅读它,因为您没有检查 stderr。您应该修改脚本以将失败步骤的 stdout 和 stderr 写入例如/tmp/$$.err 用于调试。
关于c - 当我使用 system() 从 C 调用 bash 脚本时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17145652/