473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Sending ctrl-d through a socket

I am using a TCPIP connection to communicate over port 23 (telnet) to
a server,
and I am having to mimic normal command line interface you owuld see
in a telnet session (i.e. I have to write to this socket just like you
would enter things on the keyboard if you telneted to this server).

In a normal telnet session you can enter some commands which take a
long time to complete, and they run in the background and you get the
command line prompt back, you can hit <ctrl-d> on the keyboard to see
the status of the background task and see if you get a response like
"EXECUTED" or "WORKIGN", when you hit the <enter> again you will be
back at the command line to continue working.

Context is C++ on a Unix server:
My problem is I cannot programatically mimic a <ctrl-d> input through
the socket when required, so that I can read the background response.

I have tried writing/sending all sort's of characters to emulate the
keyboard sequence of ctrl-d. I am surprised that I cannot find
anything in the usergroups related to this problem, perhaps control
characters are most usually read but never sent?

I have tried the following, but it did not work:
const char ch='^D';
ptr=&ch[0];
size=1;
nwritten = write(socketDescriptor, ptr, size);
Jul 19 '05 #1
4 13911
Scott wrote:
....
I have tried writing/sending all sort's of characters to emulate the
keyboard sequence of ctrl-d. I am surprised that I cannot find
anything in the usergroups related to this problem, perhaps control
characters are most usually read but never sent?

I have tried the following, but it did not work:
const char ch='^D';
const char ch='\004';
ptr=&ch[0];
size=1;
nwritten = write(socketDescriptor, ptr, size);


nwritten = write(socketDescriptor, &ch, size);

Maybe ?

Jul 19 '05 #2


Scott wrote:

I am using a TCPIP connection to communicate over port 23 (telnet) to
a server,
and I am having to mimic normal command line interface you owuld see
in a telnet session (i.e. I have to write to this socket just like you
would enter things on the keyboard if you telneted to this server).

In a normal telnet session you can enter some commands which take a
long time to complete, and they run in the background and you get the
command line prompt back, you can hit <ctrl-d> on the keyboard to see
the status of the background task and see if you get a response like
"EXECUTED" or "WORKIGN", when you hit the <enter> again you will be
back at the command line to continue working.

Context is C++ on a Unix server:
My problem is I cannot programatically mimic a <ctrl-d> input through
the socket when required, so that I can read the background response.

I have tried writing/sending all sort's of characters to emulate the
keyboard sequence of ctrl-d. I am surprised that I cannot find
anything in the usergroups related to this problem, perhaps control
characters are most usually read but never sent?

I have tried the following, but it did not work:
const char ch='^D';
those are 2 characters. '^' followed by the character 'D'
ptr=&ch[0];
size=1;
nwritten = write(socketDescriptor, ptr, size);


you need to send the character code for your system
On an ASCII system that would be

const char ch = 0x04;

ctrl a -> 0x01
ctrl b -> 0x02
ctrl c -> 0x03
....

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #3
klaas wrote:
[SNIP]
use EOF, it's a sumbolis integer constant defined in <iostream>,

[SNIP]

sumbolis as symbolic?

--
WW aka Attila
Jul 19 '05 #4
klaas wrote:
My problem is I cannot programatically mimic a <ctrl-d> input through
the socket when required, so that I can read the background response.

I have tried writing/sending all sort's of characters to emulate the
keyboard sequence of ctrl-d.


control-d on unix means end-of-file
on windows this would be control-z

if you want it, you can use
#include <iostream>

using std::flush;

socket_or_however_your_interface_is << EOF << flush;


This has basically no chance of working. EOF is an integer. This will
print a string representation of it's value. Try it.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Miky | last post by:
Hi, I need to send Ctrl-PgUp (or Ctrl-PgDown) to the active application but when I use SendKeys.Send("^{PGUP}"), the program understands it as just PageUp. How may I solve it? Thanks in...
2
by: ThomasG | last post by:
Hi, i've got a main (win-)application which starts a consoleapp to do some work: Dim psi As New ProcessStartInfo psi.UseShellExecute = False psi.CreateNoWindow = True...
0
by: Hugh Janus | last post by:
Hi, I am running a DOS script in memory using a thread. However, if I want to interrupt this script and stop it, what should I do? In a normal DOS window you'd press CTRL+C but I do not have...
3
by: mule | last post by:
hello all, I have a c# app that telnets into a router and issues a series of commands. All works great except I haven't figured out how to send a CTRL+C. I need this so I can kill a program that...
3
by: s99999999s2003 | last post by:
hi i have a program that works very similar to tail -f in Unix It will need a Ctrl-C in order to break out of the program. I wish to run this program using python (either thru os.system() or some...
2
by: s99999999s2003 | last post by:
hi i have a program that works very similar to tail -f in Unix It will need a Ctrl-C in order to break out of the program. I wish to run this program using python (either thru os.system() or some...
3
by: William Stacey [MVP] | last post by:
How do you send Ctrl-C to a standard input stream? Just sending 03 does not work. -- William Stacey
4
by: cartoper | last post by:
I am in a pickel, I MUST start and stop the apache web server in console mode. The only way to shut down apache cleaning is by pressing <Ctrl>+C. I have tried everything I know and I cannot...
3
by: Daniel Clark | last post by:
I have a Windows command line based application that only shuts down cleanly if it sees "CTRL-C" on the console. I need to automate the running of this application, but still allow the user sitting...
1
rhitam30111985
by: rhitam30111985 | last post by:
Hi all .. i am trying to do something really weird ... here is my code : import os os.system("mail -s test xxx@gmail.com asdaskdjkasdaasdad")
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.