Spawn xterm and issue commands using Expect - tcl

I'm trying to write a GUI using Tcl/tk where the user will select different parameters and hit a 'Submit' button. When the button is pressed, the program will open an xterm window and telnet and perform configurations based on the choices made by the user. I know this should be pretty basic but I've looked everywhere and cannot find a working method. Please advise. Thanks.

I think xterm isn't needed: Expect is able to provide a program (telnet in your case) with a pseudoterminal -- one of the things xterm does for the program it's running. So just google for this combo.

I don't believe that expect can control an X app such as xterm. It can however control a text app like telnet.
You can write a shell script that launches xterm, passing the "-e" option to execute an expect script. That expect script can then launch telnet.

Related

Invoking series of commands in a new tab in cmder

TLDR:
I want to use something like -new_console:t:tabname to open a new named tab in cmder and then transfer focus/control to that tab so that the rest of the commands I'm sending from a Python script run in that console instead. Or, I want to rename a cmder tab from a script running in the console.
DETAILS:
I often have to execute a series of commands in cmder in order to test the latest code from our continuous integration environment. Because there are several applications I often have to have running at a time, it would be helpful for me to have the cmder tabs named according to which application they are running.
The only way I've found to set a tab name from within cmder (apart from manually with mouse clicks) is to do so with the -new_console:t:tab_name command. But that only runs the next command in the newly opened tab, and not all the things that come after it.
I kick off all my commands with a Python script that accepts parameters to let me control which application opens and how things behave. I'd like to do something like this:
os.system('pwd "-new-console:t:' + args.app + '"')
so that a new tab opens with the name of the app I'm about to invoke in it, starting with an indication of the present working directory. But then I'd like all the commands that follow from the Python script to be run in this new tab instead of in the tab used to kick off the Python script. This includes printing some flowerboxed comments, but also invoking a local application server that will continue running.
Is there any way to, as you create a new (named) tab in cmder, transfer focus to that tab so that all future commands run in that tab instead of the initiating tab? Alternately, is there any way from within a cmder console to rename the cmder tab it's running in? That would be just as good.
Thanks!
Thanks for looking, but I found the answer.
In the bottom right corner is a hamburger stack. Click on that and select Settings. In General --> Tab bar, change the Console setting from the default %n to %s. Then the "title" command will change the tab name.

How to automaticallly give input in a tcl script without asking the user

I have an instruction:
delete flash:file
in my tcl script, which is to delete a file called file from the flash.
It gives the question:
delete file[confirm]?
I don't want the user to say y or n. I just want to delete it, and execute the next instructions.
Is there a way to do so?
EDIT : Okay, so I'm executing a script in a Cisco router console, where delete flash:<file_name> is an option which asks the user for confirmation (As shown above). I have included the same in the script. I am able to delete the file but I have to always press enter for confirmation which I don't want to do. I want it to always confirm the deletion. I hope I'm clear.
It is a general precautionary to prompt the user for negative operations like file deletion, closure of application and of course router or switch reload.
In that aspect, some applications may provide options to override the prompt and some may not.
In your case, it is obvious that your device will prompt for file deletion. It may be a platform specific. There may be chance that the option to override may available. But not all.
By considering these into account, you could you send and expect in your script.
A pseudo code can be something like,
send "delete flash:file\r"
expect "confirm"
send "y\r"
expect "router#"

Passing execution time parameters to TCL scripts from non interactive shell

I am able to run the TCL scripts on the linux server from the Non-interactive shell created by JSch library used in the java program from windows environment. The problem is I have some scripts which needs to pass certain parameters during the execution of the script based on the intermediate output of the script and after the parameters are entered, the script execution continues from there onwards. But as it is non interactive shell, I am not able to pass this parameters during execution. Is there any way where I can make it work ? I thought of an option where, I will pass the parameters as command line argument, but wanted to know any other way.
When you say "parameters", do you mean anything that a user would have entered in an interactive session as an input to prompts presented by the script?
If yes, there are two possibilities:
If the script does not expect the session to be interactive, and just reads its input from its standard input stream (using gets for instance), then just feed this input to the standard input of the tclsh process which interprets your script.
If the script does expect the session to be interactive (and refuses to just accept the data from its input stream), you will have to allocate a pseudo-TTY for the target process.
I'm not familiar with JSch, but this appears to be a question (and an answer) dealing with the making JSch allocate a PTY.

how to automate the testing of a text based menu

I have a text based menu running on a remote Linux host. I am using expect to ssh into this host and would like to figure out how to interact with the menus. Interaction involves arrowing up, down and using the enter and back arrow keys. For example,
Disconnect
Data Collection >
Utilities >
Save Changes
When you enter the system Disconnect is highlighted. So simply pressing enter twice you can disconnect from the system. Second enter confirms the disconnect.
The following code will ssh into my system and bring up the menu. If I remove the expect eof and try to send "\r" thinking that this would select the Disconnect menu option I get the following error: "write() failed to write anything - will sleep(1) and retry..."
#!/usr/bin/expect
set env(TERM) vt100
set password abc123
set ipaddr 162.116.11.100
set timeout -1
match_max -d 100000
spawn ssh root#$ipaddr
exp_internal 1
expect "*password:*"
send -- "$password\r"
expect "Last login: *\r"
expect eof
I have looked at the virterm and term_expect examples but cannot figure out how to tweak them to work for me. If someone can point me in the right direction I would greatly appreciate it. What I need to know is can I interact with a text based menu system and what is the correct method for doing this, examples if any exist would be great.
thanks,
-reagan
Try using the autoexpect tool to record an interactive session, and see what the codes look like.
To simplify your life, you might want to setup public key encryption so that you can ssh to the remote host without using a password. Then you can concentrate on testing your software instead of ssh. Google "ssh login without password" for more information. The instructions you will find are straight forward, so don't be afraid.
Have you tried \n\n\r?

sending command and obtaining a reply from actionscript 3 / air

I am attempting to send a command to the command line with an air/as3 application.
I have seen some documentation on the invoke command but i am wondering if anyone else has dealt with the same set of circumstances.
basically the user will be checking boxes and filling out a form which will then be written as arguments to an application that will be doing the work. this application accepts these arguments as well as a place to store the output file and processes the file.
so is it possible to send commands to the command line using as3/air and furthermore is it possible to obtain the resulting message from the command line.
I have searched a bit for this sort of information but it seems that google returns a lot of 'how to compile as3 from the command line' tutorials and there are very few articles concerning air/as3 and it's possible interactions with the system's command line.
Thank you in advance,
-Nathan
there is no way to launch apps from AIR (explanation here), nor to send anything to the command line ... however mike chambers created CommandProxy that allows you to do so, interfacing with a C# counterpart ...
greetz
back2dos
AIR 2.0 has Native Process API. Through which now its possible.