PDA

View Full Version : system function appends "?"


richardcrossley
03-10-03, 04:26
Hi,

I am writing a scheduler using perl to work in a distributed environment.
Each host will be required to run a server that will execute tasks return
their sucess or failure. I have written pretty much most of the code to
execute the tasks, but it seems the system() function is adding a "?" to the end of any file redirections. For example, if I ask it to run the command ls > /tmp/ls.txt the file /tmp/ls.txt? is created. Similarly if I ask it to run date > date.txt I get date.txt?

Output of uname:
Linux rwc3.richardcrossley.com 2.4.18-14custom #2 Mon Feb 24 08:07:17 GMT
2003 i686 i686 i386 GNU/Linux

Output of perl --version
This is perl, v5.8.0 built for i386-linux-thread-multi (etc...)

I have attached the code for the server. The problem can be recreated using the following telnet session...

telnet localhost 2345
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
START_TASK:ls >/tmp/ls.txt
SHUTDOWN
Connection closed by foreign host.


Thanks in advance.

Bernd Dulfer
03-10-03, 06:56
Telnet will send the RETURN you enter after each line to the server.
But it will be send as DOS Return: cr/lf.
Since your server runs on linux, Perl will strip only the 0x0a/lf with chomp, leaving the 0x0d/cr at the end of the string.
The filesystem converts the 0x0d to a ?.

Either strip off the 0x0d by hand using chop or change the input record separator before chomping like this:

recv (SCHEDULER, $data_read, $maxlength, 0);
{
local $/ = chr(13).chr(10);
chomp $data_read;
}

rgds

richardcrossley
03-10-03, 16:00
Many thanks I'll give that a try.

richardcrossley
03-10-03, 21:18
$/ = chr(13) . chr(10)

Works a treat.

Danke!