Writing to multiple lines in command prompt VBSCript - perl

I am writing code in VB script.
The script will executing commands for programming, erasing, verfying hex code on microcontrollers in serial production.
The vbscript executes Commad line interface which is running similar like windows command prompt.
After Ppcli.exe is started from VBScript, some commands are sent to the com port. The commamds are shown below:
Get port, OpenPort , SetPowerVoltage 3.3, SetProtocol, EraseAll,Program, ...etc.
Everything works great, but here is the problem. I can send commands in sigle string (Open Port, Set Power, Erase... etc.) but this kind of sending has a big issue.
I can't read the response for the sigle command (OK or not OK) and I can't send the whole hex file at once, because programmer only supports programming, verifying line by line. This means I have to read line from file and send it to microcontroller 128 times.
I have to send 128 commands for write lines in sigle string which is really not the good solution.
I would like to write do while loop, but every time I close command prompt window, the ports is automaticly closed and the communication is lost :(
I would like to know if is it possible to write to command line in the way to send:
Open Port
Read if it is OK or not OK
Program line form hex file 1
Verify line 1
Program Line 2
Verify line 2
etc.
I really don't know what to do, since I am not able to communicate with the programmer in any other way than single string sending. But the string is then very long and there is no diagnostic if something goes wrong while programming:(
I was sure that CLI (command line interface) would be the best choice to program microcontrollers but now I am stuck, since I didn't know that it is only possible programming row by row and not the whole hex program at once :(
If you have any solution for me I would be glad.
Can I run Perl code from VBS? I also have working pearl example for programming devices?
Thank you,

Separate commands with & sign.

Related

How to interact with a CLI program using Powershell?

Imagine I have a program writen in whatever language and compiled to run interactivelly using just command line interface. Lets imagine this one just for the sake of simplify the question:
The program first asks the user its name.
Then based on some business logic, it may ask the user age OR the user email. Only one of those.
After that it finishes with success or error.
Now image that I want to write a script in powershell that fills all that data automatically.
How can I achieve this? How can I run this program, read its questions (outputs) and then provide the correct answer (input)?
If you don't know the questions it will ask ahead of time, this would be tough.
PowerShell scripts are normally linear. Once you start the program from in PowerShell, it would wait for the program to finish before continuing. There are ways to do things in parallel, but it doesn't interact like that.
Although if you're dealing with something like a website making the first call gives a response (completing the command). You could match the response to select the proper value.
Or if the program is local and allows command line parameters, you could do that.

How to use sockets in Lua to telnet?

In Lua, I downloaded the LuaSocket library and then am trying to:
Connect using telnet
Send some commands
receive output from the commands to parse later
close telnet
What am I doing wrong with this code that is not making that work?
local socket = require("socket")
conn = socket.tcp()
conn:connect("IP Address",23)
conn:send("password")
conn:send("enable")
conn:send("password2") ;; above was all login procedure
conn:send("sh run interfaces ethernet 16")
var1 = conn:receive('*l')
print (var1)
I expected this to give me the first line of code printed off by the sh run interfaces ethernet 16 command, but all I get is 2:) 2v sqrt:) sqrt<3... That is, four random symbols that I don't know what they mean.
Any help on what I did wrong here would be greatly appreciated, thanks.
here are those four symbols:
Update: For all who were curious I needed \r to make the commands go on separate lines, and I had to put a sleep time in between each of the commands so the system would have time to load in between them. It then worked perfectly.

how to read texts on the terminal inside perl script

Is there any way to capture the texts on termianl screen inside a perl script. I know there are some functions like system,exec,backticks but the problem is that they execute commands FROM the script.For ex:- in terminal i write cd/ (or) ls,and after that i run my perl script which will read what was written on termianl screen(in this case, scipt will capture cd/ (or) ls-whichever was given to termianl). I came with one solution that by passing the commands which you wrote on termianl as a command line arguments to the script,but any other way???
Like this maybe:
history | perl -ne 'print $_'
As I understand it, in a situation where you've typed some stuff into a terminal like this:
[tai#littlerobot ~] echo "Hello"
Hello
[tai#littlerobot ~] perl myscript.pl
You want myscript.pl to be able to access the echo "Hello" part, and possibly also the Hello that was that command's output.
Perl does not provide such a feature. No programming language does or can provide such a feature because the process in which your script/program runs has no intrinsic knowledge about what happened in the same terminal before it was run. The only way it could access this text would be if it could ask the currently running terminal, which will have some record of this information (i.e. the scrollback buffer), even if it cannot distinguish between which characters in the text were typed by you, and which are output. However, I know of no terminal that exposes that information via any kind of public API.
So if you want myscript.pl to be able to access that echo "Hello", you'll need to pass it to your script. Piping history to your script (as shown by Mark Setchell in his answer) is one technique. history is a shell built-in, so it has as much knowledge as your shell has (which is not quite the same knowledge as your terminal has). In particular it can give you a list of what commands have been typed in this shell session. However, it cannot tell you about the output generated by those commands. And it cannot tell you about other shell sessions, so doing this in Perl is fairly useless:
my #history = `tcsh -c history`;
The last thing you could try (though it would be incredibly complicated to do) would be to ask the X server (or Windows if running on that operating system) for a screen shot and then attempt to locate which rectangle the current terminal is running in and perform OCR on it. This would be fraught with problems though, such as dealing with overlapping windows.
So, in summary, you cannot do this. It's nothing to do with Perl. You cannot do this in any programming language.

How to pass inputs from a script to command line

I am a new newbie to scripting, fuzzing, and buffer overflows. I understand the basic concepts behind them though.
I am looking for a way to pass input from a script (I am thinking perl) to a command line.
I am trying to create a fuzzer for a buffer overflow.
I have a basic C program that takes input from the command line
I need a script that I can pass patterns through to this external program on the command line.
Any help would be appreciated. Thank you.
You can create a file for the inputs, with 11 lines in it (last line is just an empty line to simulate enter key for the last command line input), and then redirect this file to the C program:
./c_program < file_with_10_inputs
You can save the above line as a wrapper script (e.g., auto_exec.sh) and in perl do:
system("sh auto_exec.sh");
I think you have to handle the stdin an stdout of the external process, so it's a good idea use a module like IO::Async, which helps you a lot.

Possible to use Powershell to type a command into a third-party command line program?

I have an old, third party, command line, proprietary program which I'm calling from PowerShell.
Once started, this program accepts commands typed in followed by enter (like any other program), but it's very basic. It doesn't have flags, doesn't accept piped in arguments, etc. You have to start the program, type your command, hit enter and parse the results.
Is there a way I can use PowerShell to type in a command and get the resulting output? Right now the best solution I have is to call SendKeys.Send in a background job, but I'm not sure this will work.
Is there a better way?
check out this to see if it would work for you: http://wasp.codeplex.com/
legacy programs are hard to tell, however. this works with standard windows programs.