Thread: problem running a C program in the cygwin shell in Win XP

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    17

    problem running a C program in the cygwin shell in Win XP

    Hi,

    I just installed cygwin on Windows XP. I used Visual Studio to compile a test
    C program. If I were at the shell in cygwin, and typed this command:

    $ date > tmp_file

    The content of the file tmp_file in that directory would look something like this:

    Mon Jul 27 01:22:25 PDT 2009

    So when I compiled my program that looks something like below, and ran the .exe file at the prompt at the cygwin shell, the "date" command executes, the "tmp_file" got created with the correct info, but the C program hangs. I have to press <RETURN> for the program to end.

    What causes this, and how do I fix this problem? Thanks.

    Here's the samle of that command in the C function:

    system ("date > tmp_file");

  2. #2
    Registered User
    Join Date
    Jul 2009
    Posts
    17
    It looks like it's not the UNIX commands that are causing the problem.

    If I type the Windows commands, I still have the same problem.

    I think that my syntax for the system command is not correct.

  3. #3
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Well with gcc alone, this works on my WinXP with Cygwin. By any chance are you calling getchar() at all?

    In Netbeans, I get what you get, without that, then I have to hit return to exit. My date_file is created as expected.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    date is both a cygwin command and a DOS command.

    The cygwin one just prints the date.
    The DOS one prints the current date, and prompts you for a new date. Pressing return just accepts the old date.
    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.

  5. #5
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Then running this within a cygwin shell you should be fine.

  6. #6
    Registered User
    Join Date
    Jul 2009
    Posts
    17
    OK, I just changed it to something else, like:

    system ("ls -l > tmp_file");



    The same problem occurred. The compiled program hangs when it reaches this command. To make it continue, I have to press <RETURN>. It looks like the system command is waiting for a key to be pressed by the user, before it can continue in the C program.

    What do I need to do in my C program, so that it thinks that a <RETURN> was pressed, so that it can continue?

  7. #7
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    I believe your <RETURN> is to exit out of your IDE, if that is the environment you ran your program in. Do you get this same behaviour when you execute your .exe from the command line?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with my program i cant figure out...
    By youareafever in forum C Programming
    Replies: 7
    Last Post: 11-01-2008, 11:56 PM
  2. Program problem
    By Birdhaus in forum C++ Programming
    Replies: 6
    Last Post: 11-21-2005, 10:37 PM
  3. Running my program.....estimated to take 55 hrs...
    By AssistMe in forum C Programming
    Replies: 14
    Last Post: 03-21-2005, 12:46 AM
  4. FAQ : running program inside program (spawn)
    By nipun in forum C Programming
    Replies: 3
    Last Post: 06-13-2004, 02:30 PM
  5. running a program
    By task in forum C Programming
    Replies: 1
    Last Post: 05-31-2003, 08:01 AM