AutoitNew94 Posted March 8, 2011 Posted March 8, 2011 I started a project some time ago about working with cmd.exe commands, but it has been so long I forgot how to produce the correct results. I compile as console app and I am thrown errors, either file destination does not exist, etc... What am I doing wrong here? $var = "Taste" ConsoleWrite('"cmd.exe" /k echo.' & $var) Show some different ways to work with cmd commands. Thank You. "You're not smart enough for me to open my inbox, so stop sending me mail."
guinness Posted March 8, 2011 Posted March 8, 2011 (edited) OK, firstly the Example you provided works, it writes the string to the Console in SciTE. If you want to Run cmd.exe then have a look at Run() and @ComSpec, I found this Example which might help you >> Edited March 8, 2011 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
AutoitNew94 Posted March 8, 2011 Author Posted March 8, 2011 OK, firstly the Example you provided works, it writes the string to the Console in SciTE. If you want to Run cmd.exe then have a look at Run() and @ComSpec, I found this Example which might help you >> Thank you guinness that helped, and I figured out what I was doing wrong from the compiler.My next question would be how to execute the command from the same command prompt,So when I type ConsoleTest.exe from the command line the command that's executed stays thereand is not opened in another cmd.exeThank you again. "You're not smart enough for me to open my inbox, so stop sending me mail."
guinness Posted March 8, 2011 Posted March 8, 2011 I would suggest having a look at Console.au3 by user Mat and perhaps by him as well. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
AutoitNew94 Posted March 8, 2011 Author Posted March 8, 2011 I would suggest having a look at Console.au3 by user Mat and perhaps by him as well.Thank you again. This does not solve the issue to my question.However the project looks very useful for future reference.Even when running the example _Console_Write.au3 it generates a new command window.I know it does not have to be this difficult. I was able to do this before, I have just forgottenhow.So, one more time from the top.I open up cmd.exe I run my compiled script which has cmd commands in itThe output goes directly to the same prompt window as I ran it from.So echo.Hello World!!! from my autoit script outputs to the same commandwindow from which I ran the compiled autoit script.How do I do this?Thank you again. "You're not smart enough for me to open my inbox, so stop sending me mail."
guinness Posted March 8, 2011 Posted March 8, 2011 (edited) OK, maybe #AutoIt3Wrapper_Change2CUI=Y to the top of your Script.Source: http://www.autoitscript.com/autoit3/scite/docs/AutoIt3Wrapper.htmEdit: Without having any code it's a little bit difficult to know what you have and what you don't. Edited March 8, 2011 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
AutoitNew94 Posted March 8, 2011 Author Posted March 8, 2011 OK, maybe #AutoIt3Wrapper_Change2CUI=Y to the top of your Script. Source: http://www.autoitscript.com/autoit3/scite/docs/AutoIt3Wrapper.htm Edit: Without having any code it's a little bit difficult to know what you have and what you don't. Ok so what I want to be able to do is to write a script that takes user arguments from the command line. I will call the script Whatever.exe And I want to run it as a utility from the command prompt with arguments, so... Whatever.exe echo Hello World!!! Whatever.exe dir /b /s Whatever.exe for /f "tokens=*" %x in (SomeFile.txt) do @echo.%x I would like to replace some of the commands with my own so maybe something like. echo.exe Hello World!!! dir.exe /b /s for.exe /f "tokens=*" %x in (SomeFile.txt) do @echo.%x "You're not smart enough for me to open my inbox, so stop sending me mail."
AutoitNew94 Posted March 9, 2011 Author Posted March 9, 2011 Ok so what I want to be able to do is to write a script that takes user arguments from the command line. I will call the script Whatever.exe And I want to run it as a utility from the command prompt with arguments, so... Whatever.exe echo Hello World!!! Whatever.exe dir /b /s Whatever.exe for /f "tokens=*" %x in (SomeFile.txt) do @echo.%x I would like to replace some of the commands with my own so maybe something like. echo.exe Hello World!!! dir.exe /b /s for.exe /f "tokens=*" %x in (SomeFile.txt) do @echo.%x Never mind I of course always find what I'm looking for after I make the post. Of course it is in the help file and the forums. Of course I don't know the words to look up. Of course I am a dumba$$. Problem solved. "You're not smart enough for me to open my inbox, so stop sending me mail."
AutoitNew94 Posted March 9, 2011 Author Posted March 9, 2011 (edited) So I got that part figured out. I am trying to write a couple scripts to replace some DOS commands. I am starting off with "echo" simple enough, but I am new to Autoit, so for me this is a good exercise and I despise the syntax of batch. So I have so far... If $Cmdline[0] > 0 Then For $i = 1 To $Cmdline[0] ConsoleWrite($Cmdline[$i] & " ") Next EndIf So what I would like is... ScriptName.exe Hello World This is a Test OUTPUT: Hello World This is a Test ScriptName.exe .. Hello World This is a Test OUTPUT: Hello World This is a Test ..so in the first example the string is all sent to the same line, and in the second line when specifying .. the output is split up and each token is sent to separate lines. I am sure that for that part @LF will be used easily enough. Just need to know how to react according to user input. Using if statements or how to form them properly. Thank You again. Edited March 9, 2011 by AutoitNew94 "You're not smart enough for me to open my inbox, so stop sending me mail."
AutoitNew94 Posted March 9, 2011 Author Posted March 9, 2011 (edited) Ok I solved this problem. This is great I just keep solving my own problems. =P Is there a way though to make this cleaner...? If $Cmdline[0] > 0 Then For $i = 1 To $Cmdline[0] If $Cmdline[$i] = ".." Then For $i = 2 To $Cmdline[0] ConsoleWrite($Cmdline[$i] & @LF) Next EndIf Next EndIf Edited March 9, 2011 by AutoitNew94 "You're not smart enough for me to open my inbox, so stop sending me mail."
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