您的位置:首页 > 其它

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

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

 

       先给出程序:

#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中点击“工程”,“设置”,然后填写如下:



     

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

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,  “确定”,此时会有:



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



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



     

 

      方法三:(用matlab)

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

clear
clc

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


     结果为:

test.exe

a

b

c

hello

world
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: