Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing commans to TCL-shell 1

Status
Not open for further replies.

andste

Technical User
May 9, 2003
6
SE
I can not pass commands with arguments to the shell. To make a simple example:

tcl> set b "ls"
tcl> $b

will run ls

tcl> set b "ls -al"
tcl> $b

will complain about "ls" not being a kown command.
I know that you can easily execute shell commands with exec. But i do not want to execute a shell command sice i am using a program wich has it's own commands and a tcl-prompt.

Basically i want to set a variable to a special command for that program eg: set cmd "check_timing -verbose" and then be able to execute that in the shell.




 
When i am using shell specific commands I usually have to exec them. Example

>set a [exec ls -al]


I dont have an explanation for why just ls would have worked other than maybe tcl/tk supports ls with no options.
 
The problem is that I can not use exec because it is not a shell command that I want to execute.

It is a command to the program that gives me the tcl-prompt.
 
"It is a command to the program that gives me the tcl-prompt"

I am a little bit confused, can you provide the command that is failing.
 
I am running a program called PrimeTime that does timing analysis on integrated circuits. When you start PrimeTime you get a prompt

pt>

From this prompt you can use TCL commands and internal PrimTime commands.

An example of an internal command could be:

report_timing -from point1 -to point2

This works fine if I write it directly to the prompt. But in some of my TCL scripts I use I want to be able to execute a command that is stored in a variable.

Since most people don't use PrimeTime i took the example ls -al (because I get it to work when I don't have any arguments to the command) which is a unix/linux shell command. I know you can easily execute that with the exec command. But PrimeTime commands can not.
 
No it's not. But it's a program based around a TCL-shell. So all the scripts for the program can use TCL commands. So the prompt works both as a TCL-shell and for entering PrimeTime commands.

 
Well then it sounds to me that its a scope problem. The program your running doesnt know about any of your tcl scripts. Normally i would suggest sourcing your tcl files. Try that, at your prompt type: source <file>

where <file> is the name of your file containing tcl scripts. If that doesnt work then I wont be able to help you further. Hope it helps
 
But it's in my tcl script I have a problem executing my command.

I have a proucedure

proc execute {command} {

}

where commad is a command that I want PrimeTime to execute like: &quot;report_timing -from point1 -to point2&quot;.

But I can't get the shell to execute that.
 
ok, i just did the following:

wrote small tcl file test.htk
it only had one little proc:

proc execute { command } {
$command
}


at the prompt i typed: source test.htk
and at any point after that I was able to type: execute <command> and as long as <command> runs from the prompt by itself.

 
Hi
i have developed a small application
i want to automate that...
it is a text mode application [not a GUI]
it runs from c:program exe is &quot;bob.exe&quot;
could you please writee a script for me to automatemy logon and move to next screen.



My logon screen is :[dos application/text mode]

----------------------------------------------------
USERNAME [ ]
PASSWORD [ ]
ctrl+X [Exit System]
----------------------------------------------------

Ok well my problem is to send USERname and Password simoultaneously.and then press enter to go to next screen
i used command: send &quot;$user\t$pass\r&quot; but what happens is it's just giving both id & password in some place.not in the designated columns:SO Logon is not happening

How to do that so that i can go to next screen:
----------------------------
HAI WELCOME
opt[]
-----------------------

Looking fwd for you valuable suggestion

code i developed:

set user SYS
set pass PASS /** password **/
cd $env(HOME) /**change to c:\ **/
spawn -noecho cmd
send &quot;bob\r&quot; /senidnng application command ie bob.exe **/
expect &quot;Please enter your USERNAME&quot; /*1st screen mesage**/
send &quot;SYSMAN\t&quot;
expect &quot;and PASSWORD&quot;
send &quot;PASSWORD\r&quot;
expect &quot;Exit System&quot; /*want to go to next screen*/


Please help me.
 
Please don't post multiple times.
Secondly, your post is incoherent. You say you want to
use expect from windows but the last port of expect to
windows was G.Chaffee's and is unsupported, it was quirky
and there was no interact.


Why don't you try to find a pure tcl substitute for your
logon problem?
 
Hi
i searched everywhere to find a solution for my logon problem
i dont know tcl-with expect will support this type of text mode appliccation automations! Could anybody suggest any way to automate teh logon procedure for a dos application /text mode application

The suggestion i got was ,perl will be more effiecient in doing text mode application automation.i dont know how helpful it would be since i dont know perl!

Requesting you valuable suggestions



 
Try:
set myexe [open &quot; | program.exe&quot; r+]

And use switch to read the lines of output
in a while loop, reading the programs output and
interacting with it.
example:
Code:
    while {[gets $myexe line] > -1} {
          switch -glob -- $line {
           pat1 { do_this}
           pat2 {do_that}
          }
    }
 

i am getting a message
&quot;couldn't open &quot;C:/bob.exe&quot;: permission denied&quot;
How to avoid this error!
Can we open it in read mode?

I removed &quot;r+&quot; from set myexe [open C:/bob.exe r+] .
and tried to print the lines :

set myexe [open C:/bob.exe ]
while {[gets $myexe line] > -1} {
puts &quot;$line&quot;
}

but it gives me o/p as follows:

% MZ
$µ¤

what may be the reason
Please help me out
 
You need to use the code I provided, with the pipe
'|' included.
That creates a popen() type environment.
All you're doing with your posted code is opening a
binary file and attempting to read gibberish.
 
i tried the below code as you said:

set myexe [open &quot;|BOB.exe&quot; r+]
while {[gets $myexe line] > -1} {
switch -glob -- $line {

Please enter your USERNAME { send &quot;SYSMAN&quot; }
and PASSWORD [ ] { send &quot;PASSWORD&quot; }
default { puts &quot;sorry&quot;}

}

}
-------------------------------------
But still its not getting executed .i mean no output at console.





 
Why are you using send?
This is core tcl now, not expect.


Please use the following code:

Code:
set myexe [open &quot;|BOB.exe&quot; r+]
  while {[gets $myexe line] > -1} {
        switch -glob -- $line {    
              &quot;*ERNAM*&quot;  {puts $myexe &quot;SYSMAN&quot; }
              &quot;*ASSWOR*&quot; {puts $myexe &quot;password&quot;} 
         }
  }


The other issue, and this is common, is that you need to flush the C programs internal buffers with fflush() before
output becomes visible to the tcl interpreter.
Using fconfigure, and setting buffering to line,
is also a good idea on your opened program.
 
But still i done as what you told and not able to succeed

my code just a cut and paste of your code since it was so clear:


But when i run that i just executes for a second get and get vanished

Could you please suggest how to use these fflush() and fonfigure, and setting buffering to line.
Seriously i dont know these stuff.please help me out

My code changed as below exactly as what you said:


set myexe [open &quot;|bob.exe&quot; r+]
while {[gets $myexe line] > -1} {
switch -glob -- $line {
&quot;*ERNAM*&quot; {puts $myexe &quot;SYSMAN&quot; }
&quot;*ASSWOR*&quot; {puts $myexe &quot;password&quot;}
}
}


Please reply


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top