在c++中调用exe程序进行操作

#include <Windows.h>
#include <iostream>
#include <direct.h>
#define picNum 228
using namespace std;
void main()
{

    char path[]="d:/vs/scene_text";
    if (_chdir(path)==0)
    {
        for (int picIdx=1;picIdx<=picNum;picIdx++)
        {
            char cmd_command[100];
            sprintf(cmd_command,"scenetext ./classifier1.txt ./imgs/%d.jpg ./results/",picIdx);
            system(cmd_command);
        }

    }
    else
    {
        printf("指定的路徑不存在, 或是路徑錯誤!
");
    }

}

   

system函数说明:调用一个命令处理程序去处理指令(也就是system里的command)

command参数说明:

字符串:表示要在cmd中输入的指令

空指针:只用来检查command processor是否可用,并不处理任何指令。

返回值说明:

如果command是null pointer

在processor可用的情况下,system返回非0值。反之,返回0值

如果command不为null

返回系统和库的实现值

#include <stdio.h>      /* printf */
#include <stdlib.h>     /* system, NULL, EXIT_FAILURE */

int main ()
{
  int i;
  printf ("Checking if processor is available...");
  if (system(NULL)) puts ("Ok");
    else exit (EXIT_FAILURE);
  printf ("Executing command DIR...
");
  i=system ("dir");
  printf ("The value returned was: %d.
",i);
  return 0;
原文地址:https://www.cnblogs.com/Daringoo/p/4445185.html