Send command.
Receive "command completed execution" response.
Send "hey what were my results"
Receive results from console.
####
sub sendData {
my $request = $_[0];
$responseData = ""; #class member var
print SOCKET "$request\n" . "\000" or die "print SOCKET: $!";
$responseData = ;
$responseData =~ tr/\x80-\xFF//d; #strip non printing chars > 127
$responseData =~ tr/\x00-\x08//d; #strip non printing chars > 0-8
print "resp: $responseData\n";
}
sub sendCommand{
my $command = $_[0];
$command .= "\n"; #terminate command with newline.
$responseData = ""; # member var
$commandResponse = ""; # member var
sendData(BuildWriteXML($command));
checkError($responseData); #make sure above was successful.
$responseData = "";
sendData(BuildReadXML()); #retrieve response to above command
checkError($responseData);
$commandResponse = $responseData;
}
####
my @destArray = split(/\//, $destPath); #splits path on the forward slash.
while(scalar(@destArray)) {
my $cmd = "cd \"" . $destArray[0] . "\"";
print "command: $cmd\n";
sendCommand($session, $cmd);#"cd \"" . $destArray[0] . "\"");
if ($commandResponse =~ m/Operation failed/) {
print "Debug: last cd command failed, so now create the rest of the tree.\n";
last;
}
shift (@destArray); # otherwise remove the directory from the list and continue
}
####
command: cd hello
response: [ok]
response: hello
command: cd world
response: [ok]
response: world
command: cd goodbye
response: [ok]
response: Operation failed.
####
command: cd hello
command: cd world
response:
command: cd goodbye
response: [ok]
response:
response:
command: cd happiness
response: [ok]
response: [ok]
response: world
response: hello
response: [ok]
response: Operation failed.
response: Operation failed.
####
while(responseData.indexOf("\n") == -1) { DoEvents(); } (excuse the pseudo code) or something, to poll the response and wait until a response has actually been received.