* Executable from x86_64-w64-mingw32-gcc.exe waits for input before prompt in Cygwin terminal but not Win Command Prompt
@ 2015-04-12 0:15 Randy Decker
2015-04-12 8:53 ` Corinna Vinschen
0 siblings, 1 reply; 2+ messages in thread
From: Randy Decker @ 2015-04-12 0:15 UTC (permalink / raw)
To: Cygwin
# Brief problem description
# C source file - 'printf("Test");' added as diagnostics
# Source compiles and executes in Ubuntu
# Executable compiled in cygwin terminal OK in command prompt W8.1
# - Also OK in another machine running Windows 8.1
# Same executable in cygwin term waits for input before usage hint
FROM CYGWIN64 TERMINAL
Randy@Hartford ~
$ cat countbytes.c
/* This program counts the number of bytes in a C source file.
The program prompts the user for a file name and then concatenates
the ".c" extension to this name. It uses the function getc to read
the characters.
program from "Applications Programming in ANSI C" by
Hohnsonbaugh & Kalin
*/
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
main( )
{
FILE* fptr;
char extension[] = ".c";
int char_count;
printf("Test");
printf("\n\n\tFile name (NO extension):\t");
char file_name[FILENAME_MAX]; /* defined in stdio.h*/
scanf("%s",file_name);
strcat(file_name,extension);
fptr=fopen(file_name,"rb");
for(char_count=0; getc(fptr) !=EOF; ++char_count);
printf("\n\tByte size:\t%d", char_count);
printf("\n");
fclose(fptr);
return EXIT_SUCCESS;
}
# Confirm Countbytes.exe not yet here
Randy@Hartford ~
$ ls -a
. .swp myhello.exe
.$$$ countbytes.c myhello2.exe
.. countem.exe myhelloworld.c
.bash_history countem3.exe testc.c
.bash_profile countemm.exe testit.exe
.bash_profile_temp countemm2.exe testittestc.exe
.bash_profileWin.txt countOnUbuntu.txt testtext.txt
.bashrc cygwinResults.txt welcome.exe
.bashrc_ORG Hello.c x86_64-w64-mingw32-gcc.exe
.inputrc HelloFromUnix.c
.profile HelloFromUnix-PFEvsNotepad.c
# Show alias
Randy@Hartford ~
$ alias
alias gcc='C:/cygwin64/bin/x86_64-w64-mingw32-gcc.exe'
# Compile the program
Randy@Hartford ~
$ gcc -o countbytes countbytes.c
# Verify countbytes.exe now exists
Randy@Hartford ~
$ ls
countbytes.c cygwinResults.txt Progress_Notes.txt
->countbytes.exe Hello.c testc.c
countem.exe HelloFromUnix.c testit.exe
countem3.exe HelloFromUnix-PFEvsNotepad.c testittestc.exe
countemm.exe myhello.exe testtext.txt
countemm2.exe myhello2.exe welcome.exe
countOnUbuntu.txt myhelloworld.c x86_64-w64-mingw32-gcc.exe
# Execute the output in cygwin64 terminal. Program waits with no output
# Until enter is pressed on a non blank line.
Randy@Hartford ~
$ ./countbytes
countbytes
Test
File name (NO extension):
Byte size: 865
Randy@Hartford ~
# Demonstrate same files as Cygwin64 Terminal
FROM WINDOWS 8.1 COMMAND PROMPT
Directory of C:\cygwin64\home\Randy
[.] [..]
.$$$ .bashrc
.bashrc_ORG .bash_history
.bash_profile .bash_profileWin.txt
.bash_profile_temp .inputrc
.profile .swp
countbytes.c ->countbytes.exe
countem.exe countem3.exe
countemm.exe countemm2.exe
countOnUbuntu.txt cygwinResults.txt
Hello.c HelloFromUnix-PFEvsNotepad.c
HelloFromUnix.c myhello.exe
myhello2.exe myhelloworld.c
Progress_Notes.txt testc.c
testit.exe testittestc.exe
testtext.txt welcome.exe
x86_64-w64-mingw32-gcc.exe
31 File(s) 1,289,107 bytes
2 Dir(s) 142,941,614,080 bytes free
# Execute the output in Windows command prompt terminal.
# Program PRINTS " File name (NO extension):"
# then waits Until filename is entered.
# NOTE: Execution of same code in Ubuntu 14.4 works like this.
C:\cygwin64\home\Randy>countbytes
Test
File name (NO extension): countbytes
Byte size: 865
C:\cygwin64\home\Randy>
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Executable from x86_64-w64-mingw32-gcc.exe waits for input before prompt in Cygwin terminal but not Win Command Prompt
2015-04-12 0:15 Executable from x86_64-w64-mingw32-gcc.exe waits for input before prompt in Cygwin terminal but not Win Command Prompt Randy Decker
@ 2015-04-12 8:53 ` Corinna Vinschen
0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2015-04-12 8:53 UTC (permalink / raw)
To: cygwin
[-- Attachment #1: Type: text/plain, Size: 817 bytes --]
On Apr 11 20:15, Randy Decker wrote:
> # Brief problem description
> # C source file - 'printf("Test");' added as diagnostics
> # Source compiles and executes in Ubuntu
> # Executable compiled in cygwin terminal OK in command prompt W8.1
> # - Also OK in another machine running Windows 8.1
> # Same executable in cygwin term waits for input before usage hint
It's a buffering problem. The Cygwin terminal is using a pty which is
implemented using Named Pipes for stdio descriptors under the hood. The
Windows libraries go into full buffered stdio mode. One workaround is
an explicit call to fflush(stdout) before asking for input.
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-04-12 8:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-12 0:15 Executable from x86_64-w64-mingw32-gcc.exe waits for input before prompt in Cygwin terminal but not Win Command Prompt Randy Decker
2015-04-12 8:53 ` Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).