delphi - TShellExecuteInfo lpParameters and ">" symbol -


this code calls sqlite3.exe database backup, not working because of ">" symbol in parameters. can tell me how fix it?

procedure tfadmin.dodbbackup(adbbackupfile: string); var   b, p, q: string;   ps: tshellexecuteinfo; begin    b := extractfilepath(paramstr(0)) + 'ppdb.bak';   p := extractfilepath(paramstr(0)) + 'sqlite3.exe';   q := extractfilepath(paramstr(0)) + 'ppdb.db .dump > ' + b;  //here lies problem    showmessage(p + ' ' + q);   fmain.uniconnection1.close;   try     // execute process , wait terminate     fillchar(ps, sizeof(ps), 0);     ps.cbsize := sizeof(ps);     ps.wnd := handle;     ps.lpverb := nil;     ps.fmask := see_mask_flag_no_ui or see_mask_nocloseprocess;     ps.lpfile := pchar(p);     ps.lpparameters := pchar(q);     ps.nshow := sw_shownormal;      if not shellexecuteex(@ps)       raiselastoserror;      if ps.hprocess <> 0     begin       while waitforsingleobject(ps.hprocess, 50) = wait_timeout         application.processmessages;       closehandle(ps.hprocess);     end;       fmain.uniconnection1.open;   end; end; 

the > symbol instructs command interpreter (cmd.exe) redirect output executable file. works when command interpretor running show. here, there no command interpretor.

there couple of options you. quite simple approach ask command interpretor work. use cmd.exe executable, pass /c argument, , rest of command line. if want citizen, use value of comspec environment variable rather hard coding cmd.exe.

a more grown solution abandon shell. instead call createprocess directly. little more involved. have create file handle calling createfile. pass handle createprocess standard output file handle new process. need make sure handles inherited when call createprocess.

one final point make don't wait loop. you'd far better off using msgwaitformultipleobjects block until queued messages arrive.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -