Sunday, August 2, 2009

What is the best way of sending the "enter" key manually, by code, in C?

I have a program that types in a custom-made code-defined "command" but I do not know how to have the code "press enter" after the command.





For related background, this is for terminal use:





Prompt) Enter a command


Prompt) exit.now //How to have the program press enter here is the issue.





In C++, I have seen that you can use sendkey(s), but how do you do it in C?





I had one idea that I could use fopen and fprintf with stdin.

What is the best way of sending the "enter" key manually, by code, in C?
Not exactly sure what you are asking, however,


ioctl() is the common method of setting up the terminal.


Are you writing a DOS program? Unix????


Is this a human interacting or a program interacting with another program?





if program to program, you can use piping
Reply:try appending "\r\n" to your command string.


No comments:

Post a Comment