cesinha87 Posted August 14, 2019 Share Posted August 14, 2019 Hello everyone, I am very new to AUTOIT and I am almost done with my script and I am having a hard time with the Run function....When I run the command locally in the CMD it works but when I run through the AUTOIT it doesn't Note: sqlcmd.exe command is available in the system where I am running the AutoIt Editor I've seen before here and I can't figure out. I am trying to write the final command in the Output tab (where the arrow is) to make sure the command and variables are passing correctly using CONSOLEWRITE and I am not able to do that. I tried MSGBOX as well $command = Run (@ComSpec & " /c " & 'sqlcmd.exe' & ' -S ' & $db_server_name & '\SQLEXPRESS' & ' -i ' & $sql_script & ' -O ' & $output_log, '', @SW_HIDE) ConsoleWrite ($command) Link to comment Share on other sites More sharing options...
Developers Jos Posted August 14, 2019 Developers Share Posted August 14, 2019 Are you sure it is able to find the command from the script directory? for testing purpose use: ConsoleWrite("cmd=" & @ComSpec & ' /k sqlcmd.exe -S ' & $db_server_name & '\SQLEXPRESS -i ' & $sql_script & ' -O ' & $output_log & @CRLF) $rc = Run(@ComSpec & ' /k sqlcmd.exe -S ' & $db_server_name & '\SQLEXPRESS -i ' & $sql_script & ' -O ' & $output_log, '', @SW_SHOW) ConsoleWrite("rc=" & $rc & @CRLF) and check the result. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
cesinha87 Posted August 14, 2019 Author Share Posted August 14, 2019 It looks like it's running part of the command.C:\Windows\system32\cmd.exe /k sqlcmd.exe -S WIN2K16 and it's supposed to run the entire command sqlcmd.exe -S WIN2K16\SQLEXPRESS -i "C:\Temp\Delete Duplicate SQL Query.sql" -O C:\Windows\System32\McAfeeLogs\SQL_Script_log.txt Link to comment Share on other sites More sharing options...
Developers Jos Posted August 14, 2019 Developers Share Posted August 14, 2019 The rest is on the next line which could mean there is an LF or CR character in the variable? So how are these filled and what is their exact content? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
cesinha87 Posted August 14, 2019 Author Share Posted August 14, 2019 You are right sir, there some kind LF or CR in the $db_server_name variable and I am not able to find or figure out what's going on. When I run the following script: Same script as before without $db_server_name ConsoleWrite("cmd=" & @ComSpec & ' /k sqlcmd.exe -S ' & '\SQLEXPRESS' & ' -i ' & $sql_script & ' -O ' & $output_log & @CRLF) $rc = Run(@ComSpec & ' /k sqlcmd.exe -S ' & $db_server_name & '\SQLEXPRESS' & ' -i ' & $sql_script & ' -O ' & $output_log, '', @SW_SHOW) ConsoleWrite("rc=" & $rc & @CRLF) I get the right output Here is where I am getting the $db_server_name variable (Win2k16) Global $read = $file $read = FileRead($file) $trim1 = StringInStr($read, 'db.database.name=') $position1 = StringInStr($read, "db.database.name=") ;MsgBox(0,"",$position1) $tmp = StringTrimLeft ($read, $position1+16) ;MsgBox (0, 'Database Name', $tmp) $position2 = StringInStr($tmp, 'db.instance.name=') ;MsgBox(0,"Position 2",$position2) $db_name = StringTrimRight ($tmp,StringLen ($tmp) - $position2+1) ;MsgBox (0, 'Database Name', $db_name) $trim3 = StringInStr($read, 'db.server.name=') $position3 = StringInStr($read, "db.server.name=") ;MsgBox(0,"",$position1) $tmp3 = StringTrimLeft ($read, $position3+14) ;MsgBox (0, 'Database Name', $tmp3) $position4 = StringInStr($tmp3, 'db.database.name=') ;MsgBox(0,"Position 2",$position4) $db_server_name = StringTrimRight ($tmp3,StringLen ($tmp3) - $position4+1) MsgBox (0, '$db_server_name', $db_server_name) $sql_script = '"C:\Temp\Delete Duplicate SQL Query.sql"' $output_log = "C:\Temp\output.log" ;Command to run: sqlcmd -S WIN2K16\SQLEXPRESS -i "C:\Temp\Delete Duplicate SQL Query.sql" -O C:\Windows\System32\McAfeeLogs\SQL_Script_log.txt ConsoleWrite("cmd=" & @ComSpec & ' /k sqlcmd.exe -S ' & '\SQLEXPRESS' & ' -i ' & $sql_script & ' -O ' & $output_log & @CRLF) $rc = Run(@ComSpec & ' /k sqlcmd.exe -S ' & $db_server_name & '\SQLEXPRESS' & ' -i ' & $sql_script & ' -O ' & $output_log, '', @SW_SHOW) ConsoleWrite("rc=" & $rc & @CRLF) Link to comment Share on other sites More sharing options...
cesinha87 Posted August 14, 2019 Author Share Posted August 14, 2019 I believe I just found the issue . I had a paragraph in my variable $db_server_name . Changed the SringTrimRight to $db_server_name = StringTrimRight ($tmp3,StringLen ($tmp3) - $position4+2) MsgBox (0, '$db_server_name', $db_server_name) instead $db_server_name = StringTrimRight ($tmp3,StringLen ($tmp3) - $position4+1) MsgBox (0, '$db_server_name', $db_server_name) and the command executed correctly. Thank you very mich Jos, you helped a lot Link to comment Share on other sites More sharing options...
Developers Jos Posted August 14, 2019 Developers Share Posted August 14, 2019 While typing this post as answer to your previous reply I see you found the solutions so just bare this in mind for the next time. Answer to previous post: This is way too much information. Keep it simple and start posting a simple script that is runnable and has an issue. Describe the issue and also post the SciTE output information in a simple quote (") or codebox (<>) by using these symbols at the to of the forum post window. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
cesinha87 Posted August 14, 2019 Author Share Posted August 14, 2019 Will do sir....thank you very much Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now