Jump to content
Sign in to follow this  
amakrkr

How to send parameter to script.exe

Recommended Posts

amakrkr

Hello,

i have the following script to read "selected" folder and write every file into a TXT file.

#include <Array.au3>
#include <File.au3>

$File = "c:\files\Filenames.dat"   
$Path = "c:\files\"                 
$List = _FileListToArray($Path)        
_FileWriteFromArray($File, $List, 1)

What I want to do now is a parameter or someting that will be sent to this script.

Parameter should contain a user specified path which directory should be read.

For example: c:\script.exe - c:\file\test\

I hope i made my self clear.

Thanks for your help!

PS making a GUI is not an option.

Share this post


Link to post
Share on other sites
Juvigy

Check out this topic:

http://www.autoitscript.com/forum/index.php?showtopic=115656&st=0&p=807889&#entry807889

There i try to explain how this can be done.It is all in the helpfile - command line parameters.

Share this post


Link to post
Share on other sites
amakrkr

thx mate! :mellow:

Share this post


Link to post
Share on other sites
amakrkr

Hello again,

i have encountered another problem.

What i want to do with my script, is to read manually inputed path of a directory (Check out my script in 1st post).

I have checked that thread and help file about Command Line Parameters but all i could get from it was:

$CmdLine[0] equals... 2

$CmdLine[1] equals... param1

$CmdLine[2] equals... this is another param

@ScriptName equals... myscript.au3

AutoIt3.exe myscript.au3 param1 "this is another param"

So in my opinion you can't define for example $CmdLine[1] = $X and let $CmdLine[1] to get $X from script user?

I want to make my script so, that user will define which directory will be read.

Can anyone give me another hint?

Thx for reading.

Share this post


Link to post
Share on other sites
Igzter

Hello again,

i have encountered another problem.

What i want to do with my script, is to read manually inputed path of a directory (Check out my script in 1st post).

I have checked that thread and help file about Command Line Parameters but all i could get from it was:

$CmdLine[0] equals... 2

$CmdLine[1] equals... param1

$CmdLine[2] equals... this is another param

@ScriptName equals... myscript.au3

AutoIt3.exe myscript.au3 param1 "this is another param"

So in my opinion you can't define for example $CmdLine[1] = $X and let $CmdLine[1] to get $X from script user?

I want to make my script so, that user will define which directory will be read.

Can anyone give me another hint?

Thx for reading.

Actually you confuse me here - what you described above will do exactly what you ask for (if I am not misunderstanding you). $CmdLine is an array and $CmdLine[0] holds the number of parameters passed (in your case 2) and $CmdLine[1] and onwards holds whatever parameters where passed by the user.

Ig

Edited by Igzter

Share this post


Link to post
Share on other sites
amakrkr

Hello,

thx for your replay. But i still dont understand how will program know what parameter to take.

here is my code.... i know it has a major erros in it but please give me some advices.

#include <Array.au3>
#include <File.au3>

$CmdLine[0] = 1
$CmdLine[1] 

$File = "c:\files\Filenames.dat"   
$Path = $CmdLine[1]                 
$List = _FileListToArray($Path)        
_FileWriteFromArray($File, $List, 1)

thank you.

Share this post


Link to post
Share on other sites
kev51773

Hello,

thx for your replay. But i still dont understand how will program know what parameter to take.

here is my code.... i know it has a major erros in it but please give me some advices.

#include <Array.au3>
#include <File.au3>

$CmdLine[0] = 1
$CmdLine[1] 

$File = "c:\files\Filenames.dat"   
$Path = $CmdLine[1]                 
$List = _FileListToArray($Path)        
_FileWriteFromArray($File, $List, 1)

thank you.

You're trying to set the command line parameters in the script. They already exist.

If you ran this script -

msgbox(0,$CmdLine[1],$Cmdline[2])

like this

script.exe param1 param2

you would get a messagebox with a title of 'param1' and text of 'param2'

Share this post


Link to post
Share on other sites
amakrkr

problem is that my script doesnt work. File Filenames.dat is not created and i get error "you cannot assign values to a constant".

I am just wondering what did i do wrong...

Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
kev51773

problem is that my script doesnt work. File Filenames.dat is not created and i get error "you cannot assign values to a constant".

I am just wondering what did i do wrong...

Any help would be greatly appreciated.

In which case you need to do something along the lines of...

#include <Array.au3>

#include <File.au3>

$File = "c:\files\Filenames.dat"

If $CmdLine[0] <> 1 Then

MsgBox(0,"Error","You passed " & $CmdLine[0] & " parameters, only 1 was expected")

Exit

EndIf

$Path = $CmdLine[1]

$List = _FileListToArray($Path)

_FileWriteFromArray($File, $List, 1)

If your path has spaces it will need to be enclosed in ""

Share this post


Link to post
Share on other sites
amakrkr

@ kev51773 thx for quick answer mate!

Finally i get it how it should work.

Thx again.

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  

×