Using "system()" call under Win2000

This is a discussion on Using "system()" call under Win2000 within the C Programming forums, part of the General Programming Boards category; So I have what's probably a really silly question - but here goes. I have a program I've been running ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Location
    S.F. Bay Area, CA
    Posts
    3

    Question Using "system()" call under Win2000

    So I have what's probably a really silly question - but here goes. I have a program I've been running under Win98, WinME, WinXP, but it simply doesn't work when I run it under Win2000. Well it kind of works, but when I make "system()" calls they seem to simply do nothing.

    Here's an example of one of the calls in question:

    system("copy start.dat upload.htm");

    I'm just doing a simple file copy. I don't get errors, I don't get anything actually.

    So any help would be greatly appreciated. Do I have to recompile the program under Win2000? Is there some setting on the DOS prompt window that's keeping me from executing these commands?

    Thanks for any hints.

    RC

  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    Are you running a command prompt and then your program? Is the command prompt using command.com or cmd.exe?
    Demonographic rhinology is not the only possible outcome, but why take the chance

  3. #3
    Saravanan S-CH s.saran's Avatar
    Join Date
    Dec 2004
    Location
    India
    Posts
    4
    Compile and make the executable but donít execute it through some IDE or Editor.
    Run it in command prompt, it will run.

    Note: Output Verified

  4. #4
    Registered User
    Join Date
    Jan 2005
    Location
    S.F. Bay Area, CA
    Posts
    3

    Smile

    Thanks to both of you. I have some more info. I am opening a command prompt (cmd.exe) and running my program in it. The program works fine on my desktop machine which is also running Win2000 (but not on the evil machine running the same O.S.)

    Just for the heck of it I then compiled the program on my desktop machine (so it would be compiled under Win2000 as well). Tried running that executable on the machine in question. Still no love.

    I tried making sure that all the settings on the command-prompt on the evil machine matched those on my desktop machine. Even after making sure they all matched, no luck on the evil machine.

    At this point I'm installing XP on the evil machine. If it works I'll just chock the whole thing up to the mysteries of Win2000. If not I'll be back here whining tomorrow.

    RC

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    http://www.cprogramming.com/tips/sho...ount=30&page=0

    My guess is that your problem is simply because those aren't valid programs on your machine. In Windows 2000 Microsoft didn't do a very good job of backwards-compatability (XP is better, but still not perfect). system simply sends the command you give it as a parameter to the shell, so it's almost always a better idea to use a more portable API function.

  6. #6
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Open up cmd.exe on the evil machine and type up the commands from your program to see if they even exist, like I believe sean was saying. Because the system() calls deal directly with the shell I believe. But I also believe the world was created by a giant turtle, so....

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> system("copy start.dat upload.htm");

    how hard can it be to copy a file in C?

    Code:
    int copyFile(const char * to, const char * from) {
     FILE * in, * out;
     int byte, success = 0;
     if((out = fopen(to, "wb")) != NULL) {
      if((in = fopen(from, "rb")) != NULL) {
       while((byte = fgetc(in)) != EOF) {
         fputc(byte, out);
         }
       fclose(in);
       success = 1;
       }
      fclose(out); 
      }
     return success;  
     }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  8. #8
    Registered User
    Join Date
    Jan 2005
    Location
    S.F. Bay Area, CA
    Posts
    3
    True, it's trivial to copy the file in C. However, I was using that as an example of one of the system calls I'm making. I'm also renaming files, executing and FTP script, etc.

    It's odd that it all works perfectly on one of my Win2000 machines, and doesn't work at all on the other Win2000 machine.

    RC

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,764
    > It's odd that it all works perfectly on one of my Win2000 machines,
    Do you have the same account privileges on both?

    I'm assuming that on the machine which doesn't work, that you can open a command prompt and type in
    copy start.dat upload.htm
    and it will work.

    Are things like running in the correct directory sorted out?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Saravanan S-CH s.saran's Avatar
    Join Date
    Dec 2004
    Location
    India
    Posts
    4
    >It's odd that it all works perfectly on one of my Win2000 machines, and doesn't work at all on the other Win2000 machine.

    Please make sure that the executable file and also "start.dat " present in the same directory in the other machine too.

  11. #11
    Jez
    Jez is offline
    The C-er
    Join Date
    Mar 2004
    Posts
    192
    This doesn't seem to have much to do with C - shouldn't be in the windows forum?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. minix system call pls help for project
    By porvas in forum Linux Programming
    Replies: 2
    Last Post: 06-14-2009, 03:40 AM
  2. Error C2664 - Trying to call an external Dll
    By jamez05 in forum C++ Programming
    Replies: 3
    Last Post: 08-08-2006, 07:07 AM
  3. Replies: 12
    Last Post: 05-17-2003, 06:58 AM
  4. Iterative Tree Traversal using a stack
    By BigDaddyDrew in forum C++ Programming
    Replies: 7
    Last Post: 03-10-2003, 05:44 PM
  5. call by reference and a call by value
    By IceCold in forum C Programming
    Replies: 4
    Last Post: 09-08-2001, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21