[PHP] Passing a command line w/ arguments

Status
Not open for further replies.

svdsinner

Ars Legatus Legionis
15,152
Subscriptor
We've built a custom VB app that needs to be called from a .PHP script.

The syntax from the command line (that works) is:
code:<HR>
Code:
c:\sqltoexcel.exe /UID GWILSON /URL c:\inetpub\wwwroot\Beta\Reports\test.htm

If I pass that exact line to the command line via either the back tick, exec, or shell_exec, the app runs but fails with an error indicating the parameters did not pass correctly.

If I parse that command string with escapeshellcmd, the string becomes:
code:<HR>
Code:
C:\\sqltoexcel.exe /UID GWILSON /URL C:\\inetpub\\wwwroot\\Beta\\Reports\\test.htm
This also causes the app to fail with the same error and also produces a "PHP Warning: Unexpected character in input: '\' (ASCII=92) state=1 in c:\inetpub\wwwroot\Beta\test.php on line 6"

If I parse the command string with escapeshellarg, the string becomes:
code:<HR>
Code:
'c:\sqltoexcel.exe /UID GWILSON /URL c:\inetpub\wwwroot\Beta\Reports\test.htm'
This produces the exact same failure and warning as above.

If I parse the command part with escapeshellcmd and the arguments with escapeshellarg, then the string becomes:
code:<HR>
Code:
c:\\sqltoexcel.exe '/UID GWILSON /URL c:\inetpub\wwwroot\Beta\Reports\test.htm'
This again fails in the exact same way as the above two.

If I parse the command part with escapeshellcmd and the arguments with escapeshellarg individually, then the string becomes:
code:<HR>
Code:
c:\\sqltoexcel.exe '/UID GWILSON' '/URL c:\inetpub\wwwroot\Beta\Reports\test.htm'
This again fails in the exact same way as the above three.

How the heck can I parse this string so that it will execute correctly and pass the corrent arguments? I'm going batty trying to figure it out.
 

lensam69

Ars Scholae Palatinae
746
I really don't have any idea on PHP, but it looks like your problem is the translation on the "\" chars.

Try printing the command line from the program on the screen so you can see for yourself how your program reads the command line.

Then you can make a "pre-parser" to transform the string to something that the "escapeshellcmd " and "escapeshellarg " functions can crunch correctly.


By the way, you can always write your own parser...
 
Status
Not open for further replies.