Jump to content
Sign in to follow this  
sandman

Can AutoIt work with CMD commandline?

Recommended Posts

sandman

Is it possible to set options for commandline? For example, compiled Au3 script au3.exe will create a folder when this command is given in CMD:

C:\> au3.exe create folder SHWEET
Is it possible to have AutoIt interpret this and know what to do?

I am not asking about how to interpret it, but rather if it is capable of responding to a command like this at all.


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites
tAKTelapis

Yes.. it is.

I forget how, but i am reasonably sure it is.

*EDIT*

worked it out (this should have its own section in the helpfile)

Search the helpfile (or forums) for $cmdline

its all there.

Cheers

/tAK

*EDIT 2*

for the sake of trying it out myself, here is a basic, crude example:

select
    case $cmdline[0] = 0 ; check to see if there is a parameter
        msgbox(0, "No Param", "Please specify start or end")
    Case $cmdline[1] = 'start' ; if parameter is start
        msgbox(0, "Start", "it has begun")
    Case $cmdline[1] = 'end' ; if parameter is end
        msgbox(0, "End", "all done")
    Case Else ; if parameter is other
        msgbox(0, "No Param", "Please specify start or end")
EndSelect
Exit
Edited by tAKTelapis

Share this post


Link to post
Share on other sites
sandman

Okay, thanks very much.

One more thing: Is there a way to have it print (or echo or whatever it is called in CMD) text when a command is given? Say, 'au3 eat pie'.

If $cmdline[0] > 0 And $cmdline[1] = "eat" And $cmdline[2] = "pie" Then
    MadeUpFunction("ECHOTHISBACK!!!")
EndIf
So that it would look like this in CMD:
C:\> au3 eat pie
ECHOTHISBACK!!!

C:\>

[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites
Jon

Okay, thanks very much.

One more thing: Is there a way to have it print (or echo or whatever it is called in CMD) text when a command is given? Say, 'au3 eat pie'.

If $cmdline[0] > 0 And $cmdline[1] = "eat" And $cmdline[2] = "pie" Then
    MadeUpFunction("ECHOTHISBACK!!!")
EndIf
So that it would look like this in CMD:
C:\> au3 eat pie
ECHOTHISBACK!!!

C:\>

No, AutoIt is a Windows program so it can't output to the cmd console like that.

Share this post


Link to post
Share on other sites
sandman

328 post... and you havent checked the helpfile...

http://www.autoitscript.com/autoit3/docs/i...htm#CommandLine

I've already seen that, I was asking for a different thing. Thanks, though.

@Jon: Well, would it be able to get what other programs return? Like if I called a program through ShellExecute, is there a way to get how it echoes back?


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites
PsaltyDS

I've already seen that, I was asking for a different thing. Thanks, though.

@Jon: Well, would it be able to get what other programs return? Like if I called a program through ShellExecute, is there a way to get how it echoes back?

Check out the options in Run() and RunWait() for $STDOUT_CHILD, $STDIN_CHILD, and $STDERR_CHILD combined with StdOutRead(), etc.

All of which is... wait for it... in the help file!

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
AcidCorps

is there a way to us variables in the switch, for example script.au3 /uninstall 123 would return setup.exe /uninstall 123 at the same time as script.au3 /uninstall 456 setup.exe /uninstall 456 or would I have to write out every possible switch?

Share this post


Link to post
Share on other sites
PsaltyDS

is there a way to us variables in the switch, for example script.au3 /uninstall 123 would return setup.exe /uninstall 123 at the same time as script.au3 /uninstall 456 setup.exe /uninstall 456 or would I have to write out every possible switch?

Huh...? :)

The $CmdLine array contains the parameters from the command line.

So in your first example:

$CmdLine[0] = 2
$CmdLine[1] = "/uninstall"
$CmdLine[2] = "123"

You can refer to $CmdLine[2] throughout your entire script.

Is that what you meant?

:)

Edit: Oops, CmdLine, not CommandLine... :">

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
sandman

sandman,

I'm not sure what you want - look at this:

http://www.autoitscript.com/forum/index.ph...showtopic=37626

or search title only for console in the example scripts...

sorry so late

Lol, a resurrection!

Thanks, but I am asking how to interpret commands from a CMD window, not make windows and input into them. I have figured out a solution for responding to commands, though, and here is an example:

If $cmdline[0] > 0 Then
    If $cmdline[1] = "talk" Then
        $bat = "echo ""Hello World"""
        FileWrite("respond.bat", $bat)
        If Not @error Run("respond.bat")
    EndIf
EndIf

[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites
November

Just an idea...

Just do a sticky post with that :)

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites
DaveF

I'm not sure what the original poster's task really is, but this will work unless the comsumer of the script literally is a user typing in a DOS box...

; Test to see if there was a command line argument, if not insert a placeholder
If $cmdline[0] Then
    $firstArg = $cmdline[1]
Else
    $firstArg = "(not present)"
EndIf
; Perform some operation
MsgBox(0, "Test", "The 1st argument on the command line was: " & $firstArg)
; Write a message to the console
ConsoleWrite("Writing " & $firstArg & " on STDOUT (but that doesn't mean that Windows will let you see it...)" & @CRLF)

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites
sandman

unless the comsumer of the script literally is a user typing in a DOS box...

-snip-

lol, that's what I meant this whole time, so that the user will be in CMD (same as Run>cmd) and type: myscript.exe dosomething. AutoIt will interpret the dosomething command as a command to respond, and then write and execute a batch file to respond.

@november: I'll post it in Example Scripts, see what happens :)

:):guitar::)


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

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  

×