User.1
User.1

Reputation: 2642

os.execute() with command line options

The Question: How do I execute an OS Command with three command line options in Lua ?

I have a device connected to my PC. (Windows 7, USB cables, typical corporate)

The software which controls the device is located here...

C:\Program Files (x86)\PowerUSB\

The name of the executable file (aka "Program") is...

pwrusbcmd

That program wants three single digit parameters either 1 or 0, separated by spaces

I opened a command prompt box, switched to that directory, and tested all 8 cases. All worked fine.

I then switched to another subdirectory, and tried this command...

"C:\Program Files (x86)\PowerUSB\pwrusbcmd" 1 1 1 

That also worked fine.

So I figured that the Lua command to execute that command would be either...

 os.execute("C:\Program Files (x86)\PowerUSB\pwrusbcmd 1 1 1 ")

or

 os.execute("C:\\Program Files (x86)\\PowerUSB\\pwrusbcmd 1 1 1")

Lua runs each, with no complaints, BUT, no action occurs on the device.

So I tried to alter the construction of the command itself, with the ".." connecting the two segments of the total string, like this...

 os.execute("C:\\Program Files (x86)\\PowerUSB\\pwrusbcmd".." 1 1 1 ")

Still no action.

I looked here on StackOverflow, and found

I am in sympathy with each person who wrote those questions. Much like user ID thatthing, I also tried..

So far, I can't find a single syntax construction that works.

The only "fix" (misnomer if there ever was one) I could concoct on my own is to write eight different MS-DOS bat files, and give them unique names. This renders the machine de facto unusable.

How do I get Lua to execute this command ???

C:\Program Files (x86)\PowerUSB\pwrusbcmd 1 1 1

Upvotes: 3

Views: 3350

Answers (2)

Yu Hao
Yu Hao

Reputation: 122483

You forgot to add the double quotes around the command name, the easiest way is to use single quoted strings:

os.execute('"C:\\Program Files (x86)\\PowerUSB\\pwrusbcmd" 1 1 1')

Upvotes: 4

Glitcher
Glitcher

Reputation: 1184

Try os.execute([["C:\Program Files (x86)\PowerUSB\pwrusbcmd" 1 1 1 ]])

I believe your problem is the spaces in the file path.

I know you say you used square brackets, but I can't see what combination of them you have used. This works for me.

Upvotes: 3

Related Questions