We help IT Professionals succeed at work.
Get Started

unable to redirect output thro' system in windows

not_an_xpert asked
Last Modified: 2010-04-15
hello xperts,
this ? follows the link


the code i have is this....

int main( void )
      int ret = -1;
      printf("Hello World.\n");
        ret = system("dir > c://test1.txt");
      printf(" my val is %d\n", ret);
      ret = system(" c:\\h1.exe > c:\\wierd");
      printf(" my val is %d\n", ret);
       ret = system(" c:\\h1.exe >> c:\\wierd.txt");
      printf(" my val is %d\n", ret);
//      getchar();
      return 0;

Iam trying to execute the above code in  Windows
the thing is the re-direction is not happ.  via system
But the re-direction takes place when i try it manually in the command prompt
the return value of all the above statements is 0.
As SunnyCoder had suggested in dat link..  i did have a huge code where the system was present in an if
but since things werent happ. i tried out d above sample code.

BTW is it got to do with the Library's way of implementing dis function?
But since this is a part of ANSI C library stdlib.h  shudnt this be supported by all and shudnt the behavior be same
coz i  have tried dis out in *nix b4 and i have never encountered problems  like this

not_an_xpert :-(

Watch Question
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE