Jump to content

how to make $CmdLine[] work with quotes?


E1M1
 Share

Recommended Posts

If you compile it and then execute with argument abcd then it displays you abcd but if you execute it with argument "abcd" then it still shows you abcd with out quotes. is there way to get command line arg with arg?

Problem is that when I make program that takes multiple args I need quotes too. I want to make something that would accept such commandline arg: -i "C:\some dir\file.asm" -o "C:\some other path\file.o" -d

#include <Array.au3>

If $cmdline[0] > 0 Then
$input = _ArrayToString($CmdLine, " ", 1)
MsgBox(0,0,$input)
EndIf

I know that it's possible since ffmpeg works fine with quotes in command line arg compilers also accept quotes. in command line argument.

Does anyone know how I could make my program accept quotes in commandline argument?

edited

Link to comment
Share on other sites

  • Developers

You can add the double quotes around the Filename Commandline value yourself ...so don't understand your issue here?

Edited by 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

yea but if I have -i "\path to\somefile -a" -o something then it won't work that way because you don't know if file name is somefile -a of if -a is an other arg.

or of you want to give other executable (exe file) as arg then it also wouldnt work because you cant tell if you want to give args to executable file or if you want to give args to your autoit script.

I mean -i "file.exe -a" -d If i'd add quotes manually I cant tell if a is argument for file.exe of if it's arg for my script.

Is there any workaround with dllstructs or with some other way (like some function to get raw input))? or is this Operating System related problem?

Edited by E1M1

edited

Link to comment
Share on other sites

  • Developers

Don't understand, isn't the -i parameter always followed by a file name?

I have something like this in Autoit3Wrapper which works perfectly

For $x = 1 To $CMDLINE[0]
    $T_Var = $CMDLINE[$x]
    Select
        Case $T_Var = "-i"
            $x = $x + 1
            $ScriptFile_In = $CMDLINE[$x]
        Case $T_Var = "-o"
            $x = $x + 1
            $ScriptFile_Out = $CMDLINE[$x]
        Case $T_Var = "-d"
            ; do what you need for -D
        Case Else
            ; other/wrong option
    EndSelect
Next

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

You can't have a space in the command line argument or the program will assume the next item is a new argument. If you're looking for the -i and then looking in the next array element for the parameter for -i then it will show the whole string enclosed in the parentheses as one array element, this "\path to\somefile -a" shows up in a single array element. I think your use of _arraytostring is what is confusing the matter.

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

Link to comment
Share on other sites

Well, command line parsing is sometimes very complicated.

#AutoIt3Wrapper_Change2CUI=y
#include <Array.au3>
_ArrayDisplay($CmdLine)

If you compile the script above and start it with the parameters -i "file.exe -a" -d you can see that after -i the parameter file.exe -a is given.

You can do some string manipulation to strip out the parameter for file.exe.

I hope it helps you.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

thanks. I found that single quote works. Double quote seems to be OS related problem as it also didn't work with C++ program.

so -i 'file.exe -a' -d works well

Thank you Jos for your help. I appreciate that.

edit @UEZ that's really good find. I helps alot. thank you.

Edited by E1M1

edited

Link to comment
Share on other sites

Here are the rules the cmdline-array uses to parse the commandline:

http://msdn.microsoft.com/de-de/library/17w5ykft.aspx

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...