dpvmtdu364462
2017-04-09 13:51将命令作为输入并在终端中运行的程序
I kind of know how to do this in C, but how to do it in Go?
This is the code I'm using:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_CMN_LEN 100
int main(int argc, char *argv[])
{
char cmd[MAX_CMN_LEN] = "", **p;
if (argc < 2) /*no command specified*/
{
fprintf(stderr, "Usage: ./program_name terminal_command ...");
exit(EXIT_FAILURE);
}
else
{
strcat(cmd, argv[1]);
for (p = &argv[2]; *p; p++)
{
strcat(cmd, " ");
strcat(cmd, *p);
}
system(cmd);
}
return 0;
}
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- VS2019 C语言怎么进行带有参数的调试
- c语言
- github
- c++
- git
- ide
- 1个回答
- cmd运行adb命令可以执行,pycharm运行提示adb' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
- python
- android
- 2个回答
- 将命令作为输入并在终端中运行的程序
- bash
- 1个回答
- 如何直接从终端/命令行运行Go(lang)代码?
- terminal
- unix
- command-line
- ubuntu
- 2个回答
- pycharm上运行 os.system('clear')报错,‘clear'不是内部或外部命令,cmd运行还是一样的报错,是哪里出问题了?
- python
- 2个回答
换一换