怎么用c语言调用其他程序,求助:1个调用其他程序的C语言(或C++)程序
求助:1個調(diào)用其他程序的C語言(或C++)程序
答案:3??信息版本:手機版
解決時間 2019-10-06 07:07
已解決
2019-10-06 00:29
一定是要C語言,C++也可。
讀取命令行參數(shù)(命令行參數(shù)是一個程序文件名)
執(zhí)行命令行參數(shù)對應(yīng)的程序
監(jiān)視這個程序,直到運行的程序結(jié)束后 ,本程序才退出
最佳答案
2019-10-06 01:48
Linux 下:
int main(int argc, char *argv[])
{
int child_reply_value;
char command[40];
if(argc != 2)
{
printf("[當前程序] [需執(zhí)行的文件路徑]\n");
return -1;
}
sprintf(command, "%sargv[]", "./"); //為另一個程序添加執(zhí)行命令
if(0 == fork()) //創(chuàng)建子進程
{
execlp( command, NULL ); //替換為另一個程序
}
else
{
wait(&child_reply_value); //等待子進程結(jié)束
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下的話。
要被執(zhí)行的程序要先生成一個可執(zhí)行文件。
然后用system
如system("./(可執(zhí)行文件的名字)");
這個可執(zhí)行文件應(yīng)該跟程序在同一個目錄下。
我要舉報
如果感覺以上信息為低俗/不良/侵權(quán)的信息,可以點下面鏈接進行舉報,我們會做出相應(yīng)處理,感謝你的支持!
大家都在看
推薦資訊
總結(jié)
以上是生活随笔為你收集整理的怎么用c语言调用其他程序,求助:1个调用其他程序的C语言(或C++)程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 统计学习方法+Python机器学习实践指
- 下一篇: QT网络编程——UDP