0

I run T-Plan robot which connects to my windows machine and executes some script. On successful execution of script,I export the generated xml file via pscp to my linux machine.

T-paln robot acts as a 3rd party freeware to pass some command via cmd on windows machine. This takes place by running a simple batch file on t-plan robot.However,the script which sends out command to windows disconnects itself based on some explicitly declaring timeout seconds.

I want to write a tcl code which launches this application on linux machine and once the command has generated a successful outcome as xml file and is received on linux machine,it should check whether the xml file exists on the specified directory and terminates the application right at that moment.I want this because the next code section would parse this received xml report and perform other actions.

I think there should be some class in tcl which kills the process/service on any environment ,here I need to perform that in linux.

Sincerely waiting for reply .Thanks in advance

  • Your question is rather confusing. You should try to break your overall task down into smaller pieces that you either know how to do or that you can ask about unambiguously. It's not that we can't help you get the overall solution, but we want your questions and our answers to be useful to other people too. – Donal Fellows Mar 20 '14 at 13:20
  • Thanks for the quick reply @DonalFellows .Ok so I'll just explain the part where I feel the real challenge is.I have basically two code blocks written in tcl.First one simply uses a proc to connect to windows machine ,this launches a client software (T-plan robot) which passes windows machine's IP.Now the next code block parses an xml file which is received during the run time.But this is all being done while the T-plan robot is still running.I want to kill the process as soon as the file from windows is received before the parsing block of code is being touched. – turmoilawaits Mar 21 '14 at 07:04

1 Answers1

0

To kill a process on the same Linux machine, provided you've got permission to do so (i.e., you're running as the same user), you do either:

package require Tclx
kill $processId

Or:

exec kill $processId

(The former doesn't require an external command — it does the syscall directly — but the second doesn't need the Tclx pacakge.)

Both of these require the process ID.

To test if a file exists, use file exists like this:

if {[file exists $theFilename]} {
    puts "Woohoo! $theFilename is there!"
}

To kill something on a remote machine, you need to send a command to run to that machine. Perhaps like:

exec ssh $remoteMachine kill $remotePID

Getting the $remotePID can be “interesting” and may require some considerable thought in your whole system design. If calling from Windows to Linux, replace ssh with plink. If going the other way, you're talking about doing:

exec ssh $remoteMachine taskkill /PID $remotePID

This can get very complicated, and I'm not sure if the approach you're taking right now is the right one.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215