Jump to content

Sending keystrokes in CMD


Bone09
 Share

Recommended Posts

Hello everyone,
 
I created a script that sends a series of commands on CMD through the use of 'ControlSend()' function together with 'Sleep()' after every command to ensure that the commands were sent. But when my computer somewhat slowed down, some commands were skipped out.
 
I wonder if there is a function (other than increasing the value of sleep) that waits or detects when it is already time to type in the CMD. Or maybe if there is a function that waits for the 'i-beam' to inform the program that it is already the time to send the commands.
  

Thanks!
 
; I created a function that sends the commands directly to the cmd regardless whether the window is active or not

Func Command($text)
$hWnd = WinWait("[CLASS:ConsoleWindowClass]", "", 10)
Sleep(500)
ControlSend($hWnd, "", "", $text)
EndFunc
; This is the main codeRun("cmd.exe")
Command("This is my first command")
Sleep(500) ;for the delay
Command("This is my second command")
Sleep(50) ;delay again
.
.
.
Edited by bonsantiago
Link to comment
Share on other sites

Most of the time you use StdinWrite and StdoutRead to communicate with CMD.

How do you start CMD?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I start cmd through Run(cmd.exe)

Then followed by the series of commands that I want to send.

Then please have a look at StdinWrite. The example shows how to send commands.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Another question. Are you sure the commands you want to run can't be translated to pure AutoIt?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Then please have a look at StdinWrite. The example shows how to send commands.

 

Hi, thank you for the response but I cannot use StdinWrite as this function constantly needs a directory path.

I'm actually running cmd for the purpose of executing a 3rd party application (for example a java app) through console (access the directory of the 3rd party app ONCE) and run the jar file along with the series of commands

Edited by Bone09
Link to comment
Share on other sites

I cannot use StdinWrite as this function constantly needs a directory path.

 

Can you clarify this statement? What do you mean by a function constantly needing a directory path? There's bound to be better ways to approach this. Also, I still don't see how you need to manually steer cmd.exe to access a directory through keypresses and start a java application?

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Can you clarify this statement? What do you mean by a function constantly needing a directory path? There's bound to be better ways to approach this. Also, I still don't see how you need to manually steer cmd.exe to access a directory through keypresses and start a java application?

 

The java application is not gui-based. I need to use the console to execute the commands to communicate with the program

Link to comment
Share on other sites

That is exactly what the STDxxx functions are being made for. You can send commands to the application, read the displayed data, then send another command etc.

Just give them a try.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...