Jump to content

Adding $CmdLine[1] breaks my script


leuce
 Share

Recommended Posts

G'day everyone

I'm writing a script with which a user must drag and drop a file onto it to be processed. If I include the $CmdLine[1] line in the script, the script refuses to populate a certain StringSplit array. I'm baffled... please help!

This script works:

#include <File.au3>

$cmdfile = FileOpen ("TempA.txt", 128)
$command = FileReadLine ($cmdfile)

$cmdarray = StringSplit ($command, "#", 1)

MsgBox (0, "", $cmdarray[1], 10)
MsgBox (0, "", $cmdarray[2], 10)
MsgBox (0, "", $cmdarray[3], 10)

(the second script is compiled and you drag and drop any other file onto it).

The first script runs fine and displays

One

Two

Three

but the second script displays a blank $cmdarray[1] and tells me in an error message that $cmdarray[2] has exceeded the number of subscripts.

There is NO difference between these two scripts except for that CmdLine[1] line, and that line is crucial to my script ultimately. What is wrong here?

Thanks

Samuel

Edited by leuce
Link to comment
Share on other sites

  • Developers

what is the value of $inputfile ?

It will only contain a portion of the whole filename when there are spaces in the path.

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

What is the value of $inputfile ?

The script breaks regardless of what $inputfile is. My default test file is called af.po, but I've tested it with other files too.

It will only contain a portion of the whole filename when there are spaces in the path.

No. If I try this:

#include <File.au3>

$inputfile = $CmdLine[1]
MsgBox (0, "", $inputfile, 10)

$cmdfile = FileOpen ("TempA.txt", 128)
$command = FileReadLine ($cmdfile)

$cmdarray = StringSplit ($command, "#", 1)

MsgBox (0, "", $cmdarray[1], 10)
MsgBox (0, "", $cmdarray[2], 10)
MsgBox (0, "", $cmdarray[3], 10)

Then the first message does give me the entire path of $inputfile, including spaces.

Edited by leuce
Link to comment
Share on other sites

  • Developers

The script breaks regardless of what $inputfile is. My default test file is called af.po, but I've tested it with other files too.

No. If I try this:

Then the first message does give me the entire path of $inputfile, including spaces.

Its probably a case or wrong workdir thus unable to find TempA.txt.

add this to the top of your script:

FileChangeDir(@scriptdir)

this will set the workdir correctly.

Edited by JdeB

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

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