I'm having a problem reading variables with the read command from within a script. This script is being fired from xinetd in response to connections being made on a specific port number. In the script, I have the following:
Code:
echo "U"
read username
echo "-$username-" > /dev/tty2
echo "P"
read password
echo "-$password-" > /dev/tty2
echo "M"
read machinename
echo "-$machinename- > /dev/tty2
I have the second echo in there to see exactly what is in the variables. Now I can write over the network from windoze in a program written in C++ using something such as this:
Code:
char datatoSend[256];
//Read in variable via dialog box
proxyData[strlen(datatoSend)] = '\n';
proxyData[strlen(datatoSend) + 1] = '\0';
WriteExact(datatoSend, strlen(datatoSend));
//WriteExact (not written by me) snippet
//Does the socket locking here
while (i < bytes) {
j = send(m_sock, buf+i, bytes-i, 0);
//Error checking here
i+=j;
}
Writing from windoze to the script works perfectly doing this. However, if I telnet from another linux box or from windoze on this port, the variables are read, but the end is screwed up. The first hypen will echo, then the contents of the variable, but the cursor will reset to the beginning of that line before the second hyphen echos. I'm hypothesizing that some unprintable character is embedded in the variable. Why this doesn't happen from windoze is beyond me, but I would very much like it to work with both. (At least from a C++ app on win and from a shell on linux.) Is there a command to strip out all unprintable characters from within a variable?