Reputation: 11
I am trying to read an xml file which is on my local machine and writing it to a spawned process. When I execute the code using puts and gets, the xml file is getting printed on TCl open prompt, but not on the spawned process prompt. So, after googling a bit, a command 'send' is used to send data on spawned process. But reading it through gets and then writing using send doesn't helps. I am attaching my code below. Please help. Thanks in advance.
package require Expect
package require tdom
log_file -noappend myscript.log
set spawned_machine (some IP here)
set username un
set password pw
set timeout 10
spawn plink.exe -ssh $username@$spawned_machine -pw $password
expect "*myspawnedmachine>"
exp_send "loadlicense\r"
expect "*Press CTRL-D on a blank line when done."
set filename "C:/newfolder/pqr.xml"
set size [file size $filename]
set fd[open $filename]
fconfigure $fd -buffering line
gets $fd data
while{$data != ""} {
set data1[puts $data]
gets $fd data
send $data1
}
close $fd
exp_send "\004"
expect "*myspawnedmachine>"
If I change the above logic for reading the whole pqr.xml file in one go,i.e
set filename "C:/newfolder/pqr.xml"
set size[file size $filename]
set fd[open $filename r]
set xml[read $fd]
set data[split $xml "\n"]
send $xml
close $fd
exp_send "\r"
exp_send "\004"
expect "*myspawnedmachine>"
It is sending it to spawned machine using send, but the xml file is not being sent as expected. The problem is, it is not sent properly line after line, instead all lines are being printed on the same line on spawned process. Lets consider an xml file here-
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
so, in my spawned machine this xml file is being printed as-
<?xml version="1.0"?><catalog> <book id="bk101"><author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description> </book>
That is, all on the same line.
while it is expected to be sent as,
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
I know its a lengthy question, but any help would greatly be appreciated. Thanks in advance.
Upvotes: 1
Views: 35