Jump to content
MadhaN

Script to get input from user ,check in csv file and read corresponding values and pass that value to cmd

Recommended Posts

4 hours ago, MadhaN said:

I checked in help file i cannot understand proper since i have no knowledge in scripting. 

Perhaps you should start getting some knowledge in scripting, or give up trying to script if you're unwilling or unable to learn how to. Otherwise, all you're going to do is get code you don't understand doing things you don't know, without doing anything to help yourself learn anything. We can teach you to fish, but if you're not going to pick up the pole and start fishing, you're going to find it extremely difficult to do any scripting on your own, or you could just keep begging people to barf up code for you.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
11 minutes ago, Nine said:

Brew is in a bad mood.  Happens when full moon. 

Not at all, just sick of the whining and lack of effort shown. Not knowing how to script is an excuse to learn how to, not an excuse to do nothing and expect everyone else to do it for him.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Hi all,

I made the below script which is working partially , its not searching exact match. I wanna Search Exact match . 

#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>

$sFilePath="test.csv"
$aRetArray=$sFilePath

_FileReadToArray($sFilePath, $aRetArray, $FRTA_NOCOUNT, ",")
;_ArrayDisplay($aRetArray, "2D array - no count", Default, 8)

Local $sSearch = InputBox("_ArraySearch() demo", "String to find?")
If @error Then Exit

Local $sColumn = 0 ;InputBox("_ArraySearch() demo", "Column to search?")
If @error Then Exit
$sColumn = Int($sColumn)

Local $iIndex = _ArraySearch($aRetArray, $sSearch, 0, 0, 0, 1, 1, $sColumn)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Not Found", '"' & $sSearch & '" was not found on column ' & $sColumn & '.')
Else
    ;MsgBox($MB_SYSTEMMODAL, "Found", '"' & $sSearch & '" was found in the array at position ' & $iIndex & ' on column ' & $sColumn & '.')
    MsgBox($MB_SYSTEMMODAL, "Found", '"' & $sSearch & '" was found in the array at position ' & $aRetArray[$iIndex][0] & $aRetArray[$iIndex][1] & '.')


EndIf

 

Share this post


Link to post
Share on other sites

Hai All,

Finally i created as i required. But one thing is i wanna hide the CMD , It should execute command .

 

Local $iIndex = _ArraySearch($aRetArray, $sSearch,  0, 0, 0, 2, 1,0) ; $sColumn)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Not Found", '"' & $sSearch & '" was not found on column ' & $sColumn & '.')
Else
    ;MsgBox($MB_SYSTEMMODAL, "Found", '"' & $sSearch & '" was found in the array at position ' & $iIndex & ' on column ' & $sColumn & '.')
   ; MsgBox($MB_SYSTEMMODAL, "Found", '"' & $sSearch & '" was found in the array at position ' & $aRetArray[$iIndex][0] & $aRetArray[$iIndex][1] & '.')
Run("C:\WINDOWS\system32\cmd.exe")
$win=WinWaitActive("C:\WINDOWS\system32\cmd.exe")
send('rdp /v:' & $aRetArray[$iIndex][2] &' '&'/u:'&$aRetArray[$iIndex][3] &' ' &'/p:'&$aRetArray[$iIndex][4] & "{ENTER}")

EndIf

 

Share this post


Link to post
Share on other sites

Hi all, 

Please guide me to hide the Run function ( I tried with @SW_HIDE but i cannot send variables  cmd. 

Hepo you guys will help.

Share this post


Link to post
Share on other sites

@MadhaN

If you did put the effort through which you ask for code in reading the Help file, you'd already finished your script.

In the Help file, about Run() function, there is specified:

To run DOS (console) commands, try Run(@ComSpec & " /c " & 'commandName', "", @SW_HIDE)    ; don't forget " " before "/c"

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

hI all, 

Now every thing working fine, But if i modify( increase the rows) my csv file its gives error.

Please help to resolve.

#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <Process.au3>

$sFilePath="ip.csv"
$aRetArray=$sFilePath

_FileReadToArray($sFilePath, $aRetArray, $FRTA_NOCOUNT, ",")
_ArrayDisplay($aRetArray, "2D array - no count", Default, 8)

image.png.4e47c4b0a4964111e40b5868cc276418.png

Share this post


Link to post
Share on other sites

@Nine I tried but same error , can you pls show me simple example , where i can understand clear.  Note : Am using 2d array 

 

Share this post


Link to post
Share on other sites

The error is pretty self-explanatory. You aren't giving the function an array, figure out why that is, and then go from there.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

@Nine , Hi, Am getting "1" before showing the error , after adding below line. What will be the issue.

MsgBox (0,"",@error)

Share this post


Link to post
Share on other sites

@Nine , This is my final script working fine, when i use small file (30rows and 6 column  ), But i i user file with 1000+ rows am getting error.

; using a 2D array
#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <Process.au3>

Example()

Func Example()

$aRetArray = 0

 $sFilePath="123.csv"
 $aRetArray=$sFilePath


_FileReadToArray($sFilePath, $aRetArray, $FRTA_NOCOUNT, ",")
MsgBox (0,"",@error)
_ArrayDisplay($aRetArray, "2D array - no count", Default, 8)

Local $sSearch = InputBox(" RDP", "Enter ID:")
If @error Then Exit

Local $sColumn = 0 ;InputBox("_ArraySearch() demo", "Column to search?")
If @error Then Exit
$sColumn = Int($sColumn)

Local $iIndex = _ArraySearch($aRetArray, $sSearch,  0, 0, 0, 2, 1,0) ; $sColumn)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "ID Not Found", '"' & $sSearch & '" was not found on ID ' & $sColumn & '.')
Else

_RunDos('rdp /v:' & $aRetArray[$iIndex][2] &' '&'/u:'&$aRetArray[$iIndex][3] &' ' &'/p:'&$aRetArray[$iIndex][4] & "{ENTER}")


EndIf
 FileDelete($sFilePath)
 EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites
28 minutes ago, MadhaN said:

am getting "3"  error , it mean $aArray has too many dimensions,

No, it doesn't mean that. It means you have an inconsistent CSV file, there's more fields in some of the lines than in the rest. For example some of the lines may have 4 fields separated by commas, and in others there may be 3 fields separated by commas. The error messagebox is coming after the FRTA function.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

As Drew said, some lines have not enough or too much commas.  Take a careful look at your file, it's probably a mistake you have made when entering manually the lines.  A comma is very close to a dot :)

Edited by Nine

Share this post


Link to post
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

  • Similar Content

    • By 3Jake
      Hello Smart People!
      I have a multi-column .CSV that I would like to draw information from, in order to populate (send) that info to some fields in an Oracle form.  This would be for account-creation in Oracle.

      I have the basic script to navigate (tab) through the fields in the Oracle form, but I am SUPER-new to AutoIT and don’t quite see how to get the script to import and use variables from a .CSV

      For example:

      My script just waits for the page to be active, then enters data and tabs between fields like this:

      ; Wait for the window to be active WinWaitActive("Oracle is Cool - E-Business is the Best") ; User Name Send("jsmith") Send("{TAB}") ; Password Send("Password1") Send("{TAB}") Send("Password1") Send("{TAB}") ; Description Send("John Smith") Send("{TAB}") (etc. etc. etc.…)

      The winning solution would take one row at a time, feed it into fields on the Oracle form, save, and then start in on the next row

      It looks like I’d need a combination of “FileReadToArray” ( or“FileReadLine”?) and “StringSplit” to loop through the values and set them to variables, which would then replace my current "hard-coded" values to be typed them into the form?

      I found the following example in the “Help” snippets for stringsplit()… this seems like it’s in the ballpark but I’m having some trouble wrapping this around what I’ve put together, since each entry in the array would have multiple elements per line instead of just “Day”:

      Func Example() Local $aDays = StringSplit("Mon,Tues,Wed,Thur,Fri,Sat,Sun", ",") ;Split the string of days using the delimiter "," and the default flag value. #cs The array returned will contain the following values: $aDays[1] = "Mon" $aDays[2] = "Tues" $aDays[3] = "Wed" ... $aDays[7] = "Sun" #ce For $i = 1 To $aDays[0] ; Loop through the array returned by StringSplit to display the individual values. MsgBox($MB_SYSTEMMODAL, "", "$aDays[" & $i & "] - " & $aDays[$i]) Next EndFunc ;==>Example

      This post also seems like a similar example, but I don’t need it to be so selective RE: one specific column:
      https://www.autoitscript.com/forum/topic/166261-how-to-read-csv-specific-row-and-columns


      Any advice would be appreciated!  Thanks for taking a minute to look!  
    • By Burgs
      Greetings,
        I would like to be able to write a script to send commands to the console for creation of Gstreamer pipelines.  I was thinking of something similar to this:
      Local $iPID = Run("C:\Windows\System32\cmd", "", @SW_MAXIMIZE) ;THIS OPENS THE CONSOLE...!!! if $iPID == 0 Then ConsoleWrite(@CRLF & "I DID NOT OPEN CMD...error: " & @error & @CRLF) if $iPID <> 0 Then ConsoleWrite(@CRLF & "I OPENED CMD...!!!" & @CRLF) $hCmd = WinGetHandle("C:\WINDOWS\system32\cmd.exe") if $hCmd <> 0 Then WinActivate($hCmd) ;ensure command console is active... $sOutput = Send("cd C:\gstreamer\1.0\x86_64\bin" & @CRLF, $SEND_RAW) $sOutput = Send("gst-launch-1.0 videotestsrc ! autovideosink" & @CRLF, $SEND_RAW) Sleep(3000) ControlSend($hCmd, "", "", "exit" & @CR) EndIf ;$hCmd NOT "0"... I don't really know if this is the best way to open the console and send commands into it.  I'm also not sure about how to best catch any errors that may occur...likely this needs to be accomplished with the STDOUTREAD command however I've not had experience using it before and therefore would appreciate some advice that anybody may offer. 
      Basically I'm seeking guidance on how to best automate the opening of the console, sending lines of commands to be executed, and handling any potential errors in the execution of those commands...I thank you in advance.  Regards.
    • By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
    • By SOF-TECH
      Dear all,
      Can someone show  me how to en hance the below function to write in CSV  into column  and rows the input values ? 
      I am getting this result: 

      I would like the result to be as this 

      From A1:C1 is for headers
      From A2:C2 is for input Data
      Global Const $GUI_EVENT_CLOSE = -3 $sDataFilePath = @ScriptDir & "\Records.csv" #region ### START Koda GUI section ### Form= $Form1 = GUICreate("Demo1: New Record", 580, 115) $Input1 = GUICtrlCreateInput("", 10, 30, 270, 21) $Input2 = GUICtrlCreateInput("", 300, 30, 270, 21) $Input3 = GUICtrlCreateInput("", 10, 80, 270, 21) $Label1 = GUICtrlCreateLabel("Name:", 10, 10, 35, 17) $Label2 = GUICtrlCreateLabel("ID:", 300, 10, 18, 17) $Label3 = GUICtrlCreateLabel("Phone No:", 10, 60, 55, 17) $Button1 = GUICtrlCreateButton("Save to CSV", 450, 70, 120, 30) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _ExportData() MsgBox(64, @ScriptName, "Record Saved.") EndSwitch WEnd Func _ExportData() If Not FileExists($sDataFilePath) Then FileWriteLine($sDataFilePath, "Name;ID;Phone No.;") EndIf For $i = $Input1 To $Input3 FileWrite($sDataFilePath, GUICtrlRead($i) & ";") Next FileWriteLine($sDataFilePath, "") EndFunc ;==>_ExportData May be Excel UDF has be to be added but I can manage that my self  
      Thank you in advance
    • By nacerbaaziz
      Hi dear
      With this script you can print Unicode text in the CMD screen
      the script is  easy to use
      just you  write the text that contains Unicode in the first input
      and the script automatically reflect the code in the second input
       you can copy the text to the clipboard
      or you can try printing the text in the CMD window
      I apologize to everyone for colors and shape if not appropriate
      I'm a blind man and I do not see
      Thank you for your understanding
      Greetings to all of youCmdUtM.au3
×
×
  • Create New...