怎么用c语言调用其他程序,求助:1个调用其他程序的C语言(或C++)程序
求助:1个调用其他程序的C语言(或C++)程序
答案:3 信息版本:手机版
解决时间 2019-10-06 07:07
已解决
2019-10-06 00:29
一定是要C语言,C++也可。
读取命令行参数(命令行参数是一个程序文件名)
执行命令行参数对应的程序
监视这个程序,直到运行的程序结束后 ,本程序才退出
最佳答案
2019-10-06 01:48
Linux 下:
int main(int argc, char *argv[])
{
int child_reply_value;
char command[40];
if(argc != 2)
{
printf("[当前程序] [需执行的文件路径]\n");
return -1;
}
sprintf(command, "%sargv[]", "./"); //为另一个程序添加执行命令
if(0 == fork()) //创建子进程
{
execlp( command, NULL ); //替换为另一个程序
}
else
{
wait(&child_reply_value); //等待子进程结束
printf( " child process return %d\n", rtn );
}
return 0;
}
全部回答
1楼
2019-10-06 02:53
你有没有先mex -setup? 先这样然后再mbuild -setup
我做了一下,给你参考:
>> mex -setup
please choose your compiler for building external interface (mex) files:
would you like mex to locate installed compilers [y]/n? n
select a compiler:
[1] intel c++ 9.1 (with microsoft visual c++ 2005 sp1 linker)
[2] intel visual fortran 10.1 (with microsoft visual c++ 2005 sp1 linker)
[3] intel visual fortran 9.1 (with microsoft visual c++ 2005 sp1 linker)
[4] lcc-win32 c 2.4.1
[5] microsoft visual c++ 6.0
[6] microsoft visual c++ .net 2003
[7] microsoft visual c++ 2005 sp1
[8] microsoft visual c++ 2008 express
[9] microsoft visual c++ 2008 sp1
[10] open watcom c++
[0] none
compiler: 9
your machine has a microsoft visual c++ 2008 sp1 compiler located at
e:\microsoft visual studio 9.0. do you want to use this compiler [y]/n? y
please verify your choices:
compiler: microsoft visual c++ 2008 sp1
location: e:\microsoft visual studio 9.0
are these correct [y]/n? y
***************************************************************************
warning: mex-files generated using microsoft visual c++ 2008 require
that microsoft visual studio 2008 run-time libraries be
available on the computer they are run on.
if you plan to redistribute your mex-files to other matlab
users, be sure that they have the run-time libraries.
***************************************************************************
trying to update options file: c:\mathworks\matlab\r2009a\mexopts.bat
from template: e:\softct~1\matlab~2\bin\win32\mexopts\msvc90opts.bat
done . . .
>> mbuild -setup
please choose your compiler for building standalone matlab applications:
would you like mbuild to locate installed compilers [y]/n? n
select a compiler:
[1] lcc-win32 c 2.4.1
[2] microsoft visual c++ 6.0
[3] microsoft visual c++ .net 2003
[4] microsoft visual c++ 2005 sp1
[5] microsoft visual c++ 2008 express
[6] microsoft visual c++ 2008 sp1
[0] none
compiler: 2
the default location for microsoft visual c++ compilers is c:\program files\microsoft visual studio,
but that directory does not exist on this machine.
use c:\program files\microsoft visual studio anyway [y]/n? y
please verify your choices:
compiler: microsoft visual c++ 6.0
location: c:\program files\microsoft visual studio
are these correct [y]/n? y
warning: mbuild requires that the microsoft visual c++ 6.0
directories "vc98" and "common" be located within the same parent directory.
(expected to find these directories in 'c:\program files\microsoft visual studio'.)
trying to update options file:
c:\mathworks\matlab\r2009a\compopts.bat
from template: e:\softct~1\matlab~2\bin\win32\mbuildopts\msvc60compp.bat
done . . .
2楼
2019-10-06 02:33
linux下的话。
要被执行的程序要先生成一个可执行文件。
然后用system
如system("./(可执行文件的名字)");
这个可执行文件应该跟程序在同一个目录下。
我要举报
如果感觉以上信息为低俗/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!
大家都在看
推荐资讯
总结
以上是生活随笔为你收集整理的怎么用c语言调用其他程序,求助:1个调用其他程序的C语言(或C++)程序的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 统计学习方法+Python机器学习实践指
- 下一篇: QT网络编程——UDP