Rasmi Ranjan Nayak
Rasmi Ranjan Nayak

Reputation: 11948

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

#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

Figure 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.

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.

Upvotes: 1

Views: 1035

Answers (1)

Greg Hewgill
Greg Hewgill

Reputation: 992757

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\"");

Upvotes: 4

Related Questions