c - 在 C 中的 system() 上执行命令 - linux

标签 c linux datetime posix

我运行下面的代码,

int main() {
  char settime_parameters[13]= "042122142013";
  char command[25];
  sprintf(command, "date %s", settime_parameters );
  printf("%s\n",command);
  system("commad");
}

我得到了这个输出:

date 042122142013
sh: 1: commad: not found

但是,如果我在终端上运行 date 042122142013,它可以正常工作并更改系统时间。我想知道为什么当我通过 system() 执行它时它不起作用?

谢谢。

最佳答案

你需要这个:

system(command);

没有引号。

关于c - 在 C 中的 system() 上执行命令 - linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16135891/

相关文章:

c++ - 用 c 包装一个 c++ 库? (不要 "extern c")

c - scanf 将 "junk"值赋给变量

linux - 在本地安装 zlib

linux - 在linux下运行sh文件,为什么要运行./name.sh?

mysql - 使用日期作为变量选择值

c - printf 中至少保留一位小数的 double 格式

c - 总和未正确存储

linux - 为所有用户附加 LD_LIBRARY_PATH

c# - 用中间的文本格式化 DateTime

php - mysql 到 php 的转换时间在不同服务器上不同