this has been bugging me whole weekend...i'm bit new @ please bear me.
i trying windows form button execute command line arguments passing not working. stays @ working directory...
private void convert_click(object sender, eventargs e) { string safefile = @textbox2.text; string safepass = @textbox3.text; string safedir = @textbox4.text; process test = new process(); test.startinfo.filename = "cmd.exe"; test.startinfo.useshellexecute = false; test.startinfo.workingdirectory = @safedir; test.startinfo.arguments = "sqltosafe.exe" + @safefile + "-password" + @safepass; test.startinfo.redirectstandardoutput = true; test.start(); textbox1.text = test.standardoutput.readtoend(); }
the application supposed to:
1) 1 "convert" button clicke, grab location of .exe located.
2)execute upon .exe command-line arguments such as:
c:\safetosql\safetosql.exe (location of .safe file) -password (password)
i've been searching on web figure out how work no avail. think simple solution , maybe i'm n00b @ working on getting better.
thank reading , hope can provide input on should figuring out.
it looks failed add spaces , quotation marks command-line arguments.
test.startinfo.arguments = "sqltosafe.exe" + @safefile + "-password" + @safepass;
should be:
test.startinfo.arguments = "sqltosafe.exe \"" + safefile + "\" -password \"" + safepass + "\"";
or using format string instead of concatenation, clearer , doesn't create intermediate strings:
test.startinfo.arguments = string.format("sqltosafe.exe \"{0}\" -password \"{1}\"", safefile, safepass);
the reason need quotation marks user-supplied values may contain spaces , spaces deliminate command-line parameters.
you should validate user-supplied strings make sure @ least not empty.
Comments
Post a Comment