wpf - CMD command on c# -


i need write windows form app, wpf, or console application should run command prompt:

@echo off echo test or del c:\b.txt 

the c# code needs on button it's not important now. tried this:

    using system;     using system.diagnostics;     using system.componentmodel;      private void button1_click(object sender, eventargs e)     {         process process = new process();         process.startinfo.filename = "cmd.exe";         //process.startinfo.workingdirectory = "c:\temp";         //process.startinfo.arguments = "somefile.txt";         process.start("cmd", "/dir");      } 

but can't put cmd code in ^ code.

i believe want this:

process p = new process(); processstartinfo psi = new processstartinfo("cmd.exe"); // add /c command, space, command psi.arguments = "/c dir"; p.startinfo = psi; p.start(); 

the above code allows execute commands directly in cmd.exe instance. example, launch command prompt , see directory, assign arguments property of processstartinfo instance "/c dir", means execute command called dir.

another approach use seen here:

// put dos commands in batch file processstartinfo startinfo = new processstartinfo("action.bat"); startinfo.useshellexecute = true; startinfo.workingdirectory = "c:\\dir";  process.start(startinfo); 

put above code in click event.

create batch file commands using instructions found @ http://www.ehow.com/how_6534808_create-batch-files.html

in code example, if name batch file 'action.bat' , place in th c:dir folder, work way want.

cheers :)


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -