PDA

View Full Version : Passing arguments to vizard script


hotspur1
03-27-2003, 11:29 AM
Farshid,

Thanks for your help on starting Vizard from the command line. I have another related question.

Is it possible to pass other arguments to the Vizard script from the command line, i.e.,

>"C:\Program Files\Vizard\bin\Vizard.exe" myscript.py arg1 arg2 -r

That is, I want to be able to use arg1 and arg2 for other things within my Vizard script.

Thanks,
Andy

farshizzo
03-27-2003, 11:39 AM
Hi Andy,

Currently the only argument available is "-r" which runs the file.
I just added another argument "-e" which exits the program. This will be available in the next release. If there are other arguments you'd like to pass, just request them here and I'll see what I can do =)

-- farshid

hotspur1
03-27-2003, 11:56 AM
Well, one example of what I'd like to do is pass the name of another file that I'd like my Vizard script to open and write to. So if I typed the following, for example:

>"C:\Program Files\Vizard\bin\Vizard.exe" myscript.py -r out.dat

Then somewhere in myscript.py, I could use sys.argv to retrieve the filename (out.dat) then open it to write some data to it, for example.

Maybe the way to go is like the typical UNIX args, which call for something like

>Vizard.exe -r myscript.py -a arg1 arg2 ...

where -r indicates the script that should be run, and -a indicates additional arguments that should be passed to the script.

Thanks
Andy

farshizzo
03-27-2003, 02:58 PM
Hi Andy,

That sounds easy enough =)
I'll try to add the "-a" command in the next release.

-- farshid

farshizzo
04-25-2003, 12:31 PM
Hi Andy,

I just wanted to update you on a new feature of vizard.
You can now pass arguments to a script from the command line.
For example if you wanted to specify an input and output file you would do the following:

>"C:\...\Vizard.exe" myscript.py -r -a in.dat out.dat

Then in your vizard script you would read in the arguments through the variable 'viz.args', which is a list of strings. In the example above, viz.args would be ['in.dat','out.dat']

-- farshid

hotspur1
05-01-2003, 07:06 AM
Hi Farshid,

I've just tested it out and it works as advertised - thanks.

Andy
:)

hotspur1
05-01-2003, 03:36 PM
Hi Farshid,

Sorry to bother you again, but I did notice some odd behavior when passing args from the command line. I wanted to pass more than one arg, so I tried grabbing the first one using

viz.args[0]

Now this works fine according to the Vizard interactive window output, but when I check the DOS command window, it shows up as an empty list! I also get an error that the index is not valid!

As I understand the engine, the script is actually parsed twice, so perhaps the variable is getting lost when sent through the second time!

I tried copying the list to another variable using

arglist = viz.args

but the same behavior occurs. The Vizard window has happy output, but the DOS window shows an empty list. As long as I don't try to access the string, the program will obviously runs, but when I try to access a list member, it obviously can't find it.

Any suggestions?

Thanks
Andy

farshizzo
05-02-2003, 02:03 PM
Hi Andy,

That's my mistake. You are correct about the script being parsed twice, and I simply forgot to set the args for the second parse. I'll fix this as soon as possible. Sorry about that.

-- farshid