Sign in to follow this  
Followers 0
AutoitNew94

Simple question regarding working with CMD.EXE

10 posts in this topic

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."

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

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 there

and is not opened in another cmd.exe

Thank you again.


"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites

I would suggest having a look at Console.au3 by user Mat and perhaps by him as well.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

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 forgotten

how.

So, one more time from the top.

I open up cmd.exe I run my compiled script which has cmd commands in it

The 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 command

window 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."

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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. :)

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

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."

Share this post


Link to post
Share on other sites

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."

Share this post


Link to post
Share on other sites

#9 ·  Posted (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 by AutoitNew94

"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites

#10 ·  Posted (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 by AutoitNew94

"You're not smart enough for me to open my inbox, so stop sending me mail."

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
Sign in to follow this  
Followers 0