I am trying to implement launching PuTTY with AutoIt.
I have a PuTTY configuration session, I named it 'testcom11'. It saves a PuTTY session with settings for com11, baudrate and so on.
I implemented in AutoIt a line as following:
Run ("putty -load testcom11")
It works fine. I was able to launch PuTTY with my session and PuTTY windows pops up and I was able to type an 'AT' command to the PuTTY window.
Now I want, instead of hard coding one session name, to pass a session name from the command line like this:
myAutoItprogram.exe testcom11
I put this line in AutoIt:
$cmp = $CmdLine[1]
I can see it passed correctly when I print (display it with, let's say, MsgBox) $cmp, it shows testcom11.
In the next line I have:
Run ("putty -load $cmp")
However, AutoIt launches PuTTY only with the window asking me to load a session. So clearly it didn't read the -load $cmp option.
As you can see I am novice to AutoIt, so maybe you can see if it is something with how it handles $cmp in Run Window or something else.
Your syntax is bad.
AutoIt is maybe similar to PHP, but...
$a = "x"
$b = "$ay"
if you print $b you will get this text $ay
The correct way would be
$b = $a & "y"
Now $b will print xy.
So in your case its
Run("putty -load " & $cmp)
instead of
Run ("putty -load $cmp")
Also about the AutoIt Commandline. There is $CmdLineRaw and it will get the whole commandline. In order to get every parameter separated, you can use $CmdLine[n] (with n being replaced by each parameters index).
Maybe its better to use $CmdLineRaw, because you pass only one parameter, and you might avoid a possible problem if that parameter has a space in it.
Related
the title might be slightly confusing but what I need is a method to hand over pre-configured parameters to a batchfile on windows commandline.
The batchflie executes several progams (openssl) that need interactive input. To avoid this, I wrote all necessary input parameters to a textflie and now try to do something like:
type parameters.txt | mybatchfile.bat
Unfortunately this doesn't work.
Is there a way to do this?
Passing text into stdin of interactive prompts of console programs sometimes works, but needs to be done on single line of specific program. Tested way for SSH communication in batch file:
some batch code
echo n| plink.exe -pw "somepassword" root#somehost someremotecommand
some batch code
https://the.earth.li/~sgtatham/putty/latest/w32/plink.exe
Some times that I have a command ready to press enter but that command I have changed it in some way and it's a long command, then I remember that I have to open a text file (e.g. to get some information that I will use in the command). So what most of the times I do, is to cancel that command (Ctrl+C) and then open the text file get the information I need and then retype the command again with the pasted value from the text file. This is not very efficient for me specially if the server doesn't have any kind of GUI and I can't copy the previous command so I don't lose it.
So my question is, Is there any kind of combination keys that I could use to save a command ready to enter so I don't lose it and I don't have to type it all over again?
Thanks!
This is currently not possible out of the box.
The easiest way to do it is probably to
Change the cancel binding to stash the commandline
Add a binding to recall the stashed commandline
It would work something like this:
The function to recall:
function recall_commandline
if set -q stashed_commandline
commandline -r -- $stashed_commandline
end
end
Add to __fish_cancel_commandline (use funced __fish_cancel_commandline. Once you are happy do funcsave __fish_cancel_commandline):
set -g stashed_commandline $cmd
# right before:
commandline ""
Add to fish_user_key_bindings
bind \cr recall_commandline
This will allow you to press Ctrl+r to recall the last cancelled commandline. Expanding it to multiple is non-trivial (since "commandlines" can have multiple lines), as is adding the commandlines to history so that they can be recalled with the normal bindings.
I have the following function to turn comment/uncomment the current statement:
function toggle-comment-cmd-buffer --description 'Comment/Uncomment the current or every line'
set -l cmdlines (commandline -b)
if test "$cmdlines" = ""
return
end
set -l cmdlines (printf '%s\n' '#'$cmdlines | string replace -r '^##' '')
commandline -r $cmdlines
string match -q '#*' $cmdlines[1]; and commandline -f execute
end
I bind it thusly: bind \e\# toggle-comment-cmd-buffer. This way I can quickly comment and put the current statement in my command history in order to do something else. Then I can recall the comment and press [alt-#] again to remove the comment characters and continue modifying the command.
I set this up in my personal fish config because I had gotten used to doing something similar in ksh93.
I have to build one application which on button click starts passing command with putty.exe how can it be done with process.start ?
Process.start(#"C:\putty.exe")
ProcessStartInfo startinfo = new ProcessStartInfo();
startInfo.FileName=#"C:\putty.exe"
startInfo.Arguments = "some load session";
this is my current code but i want to push certain script and commands to putty terminal as well
It looks like PuTTY's command line support is rather minimal, but the -m option may work:
From http://the.earth.li/~sgtatham/putty/0.67/htmldoc/Chapter3.html#using-cmdline
3.8.3.6 -m: read a remote command or script from a file
The -m option performs a similar function to the ‘Remote command’ box in the SSH panel of the PuTTY configuration box (see section 4.18.1). However, the -m option expects to be given a local file name, and it will read a command from that file.
With some servers (particularly Unix systems), you can even put multiple lines in this file and execute more than one command in sequence, or a whole shell script; but this is arguably an abuse, and cannot be expected to work on all servers. In particular, it is known not to work with certain ‘embedded’ servers, such as Cisco routers.
You'll have to put your command(s) in a file before and pass that to PuTTY, but for simple tasks, it could work.
As mentioned in a comment on the question, Plink sounds much more amenable to what you're trying to do, as it (appears to) support a fully interactive session via the StandardInput and StandardOutput properties on the object you'll get back from Process.Start().
Is there a way to run the same command on all the open terminal tabs . I usually log into many servers and want to perform the same command on all of them. Xshell (available on windows only) had this feature where you can run same command on all open terminals , i am wondering if its possible in mac somehow ?
It is most definitely possible. I do it quite often. This solves it:
onall () {
if [[ $1 == "--help" ]]; then
echo "Usage: onall <command>"
return 0
fi
osascript -e "tell application \"Terminal\"
repeat with w in windows
repeat with t in tabs of w
do script \"${1//\"/\\\"}\" in t
end repeat
end repeat
end tell"
}
osascript is the command-line program to run AppleScript code and the -e option tells it to use the following string as the script. The ${1//\"/\\\"} escapes all of the quotes in the command.
You can either declare it as is in your .bash_profile or whatever other file you use or you can take it out of the function, put it into a script, make the script executable and put it somewhere that is always in your PATH.
NOTE 1: The entire command must be in the first argument.
NOTE 2: If you're doing a command with quotes in it, you must escape the quotes.
For example, onall echo "*" will not give the expected results. Instead, use onall "echo \"*\""
iTerm2 can solve this problem.
steps:
split terminal as per your requirement
click on shell -> broadcast input (select broadcast setting as per you requirement)
Screen shot for reference:
Instead of using Terminal for this, use SSH. If it's a command you need to run in a terminal, odds are you're sshing somewhere anyway - eliminate the middle man.
Generate passwordless ssh keypair, put the public key on the remote systems, then from a single shell script you can do something like
for host in host1 host2 host3 ..; do
ssh -i ~/.ssh/my_private_key username#${host} "echo HAXXXXXXXXXXXX | wall"
done
This is a very crude mechanism, but it's lightyears beyond having to physically open a terminal for each command.
I actually know of something that'll do what you want on OSX, but honestly it's such a generically bad idea it would be negligent of me to provide a hyperlink to it.
Is there a way, to send commands to another command-line program?
'Cause i have a special command-line program, but I can't send commands to it using syntax like program.exe something_to_do
the program executes something like this: ("here syntax" is where i want to input text to and also enter to start)
TheWhateverCommandLineProgram
Version 1.1
Give an option: "here syntax"
the program in code looks something like this:
echo TheWhateverCommandLineProgram
echo Version 1.1
Set opt=
set /p opt=Give an option:
if %opt%==command1 goto com1
if %opt%==command2 goto com2
...
Well, i guess so cause it wasnt me who made it (btw: off course its not called TheWhateverCommandLineProgram)
If you just want to give keyboard input to a commandline program you can just use echo and pipe it:
echo some text | program.exe
If you need more lines, then write them to a file and use input redirection:
echo one line > file
echo second line >> file
program.exe < file
I'm not 100% sure I understand what you're looking for. Here's two options:
You have two windows, each running a batch program. Let's say they are called myscript1.bat and myscript2.bat. You want to send a set of commands from myscript1.bat to be executed by myscript2.bat
You have a single batch script named myscript.bat, which executes a single program named program.exe. You want program.exe to execute some commands, or do some something.
Are either of these what you're looking for? Here's some idea:
Make myscript1.bat create a third file, mycommands.bat. Once myscript2.bat sees the file mycommands.bat exists, it will execute it and delete it. (Wow. Lame.)
Use Windows Scripting Host command (it's built in to Windows since Win2K) or Powershell (usually on most computers nowadays, if they have been updated). Either of these can send keystrokes to another program. Using those keystrokes, you can control the other program.
In what form does the other program take input? From the command prompt?
If the latter then I recommend Autohotkey: http://www.autohotkey.com/
You can use Autohotkey as a bridge and it will send the command as keypresses to the window of the other batch file.
You can ask for help in their forum. They are quite helpful.