如何用命令行法和系统调用法运行 exe

               

       我们知道,人与操作系统进行交互有两种基本的方式:命令行和系统调用(通过软件).下面的第一种方法和第三种方法实际上就是系统调用法,而第二种方法实际上就是命令行法.

 

       先给出程序:

#include<iostream>using namespace std;int main(int argc, char *argv[])int i; for(i = 0; i < argc; i++) {  cout << argv[i] << endl; } return 0;}


      方法一:(直接用VC6.0的IDE)

      在VC6.0中点击“工程”,“设置”,然后填写如下:

如何用命令行法和系统调用法运行 exe

     

        编译链接运行程序,结果为:(上面的工作目录为默认目录)

C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\桌面\MYCPP\Debug\test.exe
a
b
c
hello
world


 

      方法二:(用命令行)

      编译链接上面的程序,会生成 test.exe.(直接点击发现test.exe(在C:\Documents and Settings\Administrator\桌面\myCpp\Debug目录下), 发现一闪而过,看不到结果,此时可以用命令行法). 点击电脑左下角的“开始”,“运行”,输入cmd,  “确定”,此时会有:

如何用命令行法和系统调用法运行 exe

      在其中输入:cd C:\Documents and Settings\Administrator\桌面\myCpp\Debug,回车, 结果为:

如何用命令行法和系统调用法运行 exe

      然后输入:test.exe a b c hello world,然后回车,结果为:

如何用命令行法和系统调用法运行 exe

     

 

      方法三:(用matlab)

      利用matlab来启动test.exe, matlab代码为:

clearclccd('C:\Documents and Settings\Administrator\桌面\myCpp\Debug');cmd = 'test.exe a b c hello world';system(cmd);


     结果为:

test.exe
a
b
c
hello
world

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.****.net/jiangjunshow