Link to home
Start Free TrialLog in
Avatar of dsmatom
dsmatom

asked on

CreateProcess and Double Quotes

Hello experts, could somebody please help me!

If i do this everything seems OK and the executable runs with correct command line.

ExecuteString: String;
ExecuteString:='d:\visual pinball\vpinball.exe -play -"d:\visual pinball\tables\addams family 6.3.vpt"';
CreateOK := CreateProcess(Nil, PChar(ExecuteString), nil, nil,False,
              CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS,
              nil, nil, StartInfo, ProcInfo);

But if I do this (preferred option) the executable runs but does not start the passed command line arg.

ExecuteString: String;
ProgramName:String;
TablesPath:String;
CommandLineArg:String;
ExecuteString:= ProgramName+' -play -"'+TablesPath+'\'+CommandLineArg+'.vpt"';
CreateOK := CreateProcess(Nil, PChar(ExecuteString), nil, nil,False,
              CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS,
              nil, nil, StartInfo, ProcInfo);

When I do a ShowMessage(ExecuteString) the ExecuteString looks perfect!  I dont know what i'm doing wrong.

I hope this is enough information and thanks in advance.

ASKER CERTIFIED SOLUTION
Avatar of Johnjces
Johnjces
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dsmatom
dsmatom

ASKER

Thanks Johnjces.
Still same problem in that the vpinball.exe complains about "error opening file".

With your suggestion, the ShowMessage(ExecuteString) reads as follows:

d:\visual pinball\vpinball.exe -play -'d:\visual pinball\tables\addams family 6.3.vpt'

but it should put the command line arg of the table in double quotes not single that is
should be

d:\visual pinball\vpinball.exe -play -"d:\visual pinball\tables\addams famil 6.3.vpt"


Thanks again
Avatar of dsmatom

ASKER


OK my bad, sorry I worked it out.

My CommandLineArg was being prefaced with a leading space character because I had this
CommandLineArg:= (CommandLineArg+' '+ParamStr(i));
Because the command line arg are multiple words usually separated by spaces.

So I now remove the leading space character and all works well.

Thanks Johnjces.

I'm accepting your reply cause I've learnt something from you anyway...
I'm very green when it comes to Delphi.

Thanks again.