bhushanchanda
23rd May 2013, 22:58
Hello,
I was just wondering if there is any way to execute commands in command prompt (Windows). I used app_start to start the command prompt but I need to know, how can I execute multiple commands thorugh command prompt.
Like, the command prompt will pop up and will execute a few commands and then will exit.
I know, we can directly call a bat file, but was just wondering if there is any way to execute the commands through script.
mark_h
25th May 2013, 05:05
Is there a reason to not use a bat file? That is the only way I know how to do it. Other than that the most I do is run one command at a time thru app_start.
bhushanchanda
25th May 2013, 10:48
Hi Mark,
Thanks for the response. Well, actually, I want to execute the commands on the basis of conditions, so I wanted to know, if I can pass the commands through app_start.
You said, you can pass the arguments through app_start. Can you share the code to execute a single command in command prompt? The second option I got is to call a vb script which will execute commands, but well, that will be a tedious way.
mark_h
26th May 2013, 00:24
All I do is build the string that runs with app_start. So for example if a user runs a session with three reports then, based off the report - I would run excel report1macro, or excel report2macro, etc. So I basically build the command string based off user selections. We actually use tables to hold which session, which report and which macro to run. I am not sure that is what you are looking for.
Now what you could do is build a bat file, download it to the client and then execute it. Nothing special needed just open a tempfile, put in the commands you want, use server2client, then use app_start to run the bat file.
bhushanchanda
26th May 2013, 08:01
Hi Mark,
Thanks. That was a good idea. Now, I will tell you what I need. The problem is that I need to execute telnet commands which is like, if I execute a command, I will need to wait for a few seconds to execute next command and it doesnt work when I use a bat file.
My commands are like:-
telnet mail.my_mail_domain 25 | After this command I need to wait for 2 seconds and then I execute next commands which are :-
helo my_domain
mail from...
...
So, the problem is, when I use a bat file and write all these stuff, it executes 1st command line only.
If I call app_start again, I guess it will start a new window of command prompt and it wont work then.
mark_h
27th May 2013, 19:52
I see what you are saying. You are starting a telnet session and now need to send commands to it. I have never tried it, but can't you send telnet itself a command file(or script) to use? Seems to me there was a way to do this in UNIX, but I am not sure windows works the say way. Maybe something using windows command redirection. (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true)
bhushanchanda
28th May 2013, 09:53
Hi Mark,
Thanks again for the reply. Unfortunately, telnet is not supporting redirection. I have found a second way to do it. What I did, is created a VB script which has the commands and actions and I just called that script from command prompt. But the only problem remains is that I am not able to close the command prompt box at the client computer which pops up when I do app_start which will not be a bigger issue.
If it were just normal commands I would have called a bat file but its a telnet session, so bat file doesn't work with that.
Ivanus
10th December 2015, 16:20
Hi,
do you still using the VB-Script? If yes can you show me how it looks like ?
Thanks
bhushanchanda
11th December 2015, 08:01
I got it from one of the forums. Don't remember the exact name but I believe there are many of them.
Here is one - http://www.makeuseof.com/tag/automate-telnet-commands-vb-script/
You can google and get it. Unfortunately I do not have it anymore as I found better ways to do the task I was looking to do. Can you explain what is your requirement?