Search code examples
vb6

Visual Basic 6.0 Shell command with spaces breaks


I am using the VB6 Shell command to run a program.

I am using the following syntax:

cmdline = "C:\Program Files\1\common\php\php.exe C:\Program Files\1\common\rpt\spc.php " & WorkOrderNo
taskId = Shell(cmdline, vbNormalFocus)

There seems to be an issue with the space between Program Files because the PHP command spc.php doesn't seem to execute. I can see a command window come up but it disappears too fast for me to read any errors. I can run the command application by hand just fine, just not using Shell.

How can I Shell using a path with spaces in it?


Solution

  • You need to properly quote the paths in the command line, i.e.,

    cmdline = """C:\Program Files\1\common\php\php.exe"" ""C:\Program Files\1\common\rpt\spc.php"" " & WorkOrderNo