简体   繁体   English

从C中的另一个程序执行程序

[英]executing a program from another program in C

I am trying to launch a program from another program. 我正在尝试从另一个程序启动一个程序。

Here is the code below 这是下面的代码
Figure :1 图1

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
int main()
{
    printf("Before Execution \n");
    system("c:\\Rasmi Personal\\PERSONAL\\C\\Code Block\\C_Test\\bin\\Debug\\C_Test.exe");
    printf("\nAfter Execution \n");
    return 0;
}

In c:\\Rasmi Personal\\PERSONAL\\C\\Code Block\\C_Test\\bin\\Debug\\C_Test project contains the code is 在c:\\ Rasmi Personal \\ PERSONAL \\ C \\ Code Block \\ C_Test \\ bin \\ Debug \\ C_Test项目中包含的代码是

Figure 2: 图2:

#include <stdio.h>
int main()
{
     int x = 10;
     while( x --> 0 ) // x goes to 0
     {
        printf("%d\n", x);
     } return 0;
}

But while executing the 1st program (Figure 1) the output comes as below. 但在执行第一个程序(图1)时,输出如下所示。

Before Execution
'c:\Rasmi' is not recognized as an internal or external command,
operable program or batch file.

After Execution

Please help me in solving this. 请帮我解决这个问题。

PS:- I am using CODE::BLOCKS in Windows XP. PS: - 我在Windows XP中使用CODE :: BLOCKS。

You're using path names with spaces in them. 您正在使用带有空格的路径名。 Everything gets more confusing when you do that, and you have to add quotes around the right things in the right places to get anything to work. 当你这样做时,一切都变得更加混乱,你必须在正确的地方添加正确的东西以引导任何工作。

I recommend using path names without spaces in them. 我建议使用不带空格的路径名。

If you still want to try to make this work with spaces in your path names, the following might do it: 如果您仍想尝试在路径名中使用空格,则可能会执行以下操作:

system("\"c:\\Rasmi Personal\\PERSONAL\\C\\Code Block\\C_Test\\bin\\Debug\\C_Test.exe\"");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM