Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C # to call notepad program

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to use the notepad program for calling C#". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The realization of C # calling notepad program to edit the text file its System.Diagnostics.Process.Start (Info) is the main statement in the whole program. If you are only trying to execute an external program separately, you can use the following code:

System.Diagnostics.Process.Start (\ "external program name\",\ "startup parameters\")

Example demonstration of C # calling notepad program to edit text file

UsingSystem; classtest {staticvoidMain () {/ / declares a program information class System.Diagnostics.ProcessStartInfoInfo= newSystem.Diagnostics.ProcessStartInfo (); / / C # calls notepad to edit the text file external program name Info.FileName=\ "notepad.exe\"; / / sets the external program startup parameter (command line argument) to test.txt Info.Arguments=\ "test.txt\" / / set the external program working directory to C:\ Info.WorkingDirectory=\ "C:\"; / / C # call notepad program to edit the text file declaration a program class System.Diagnostics.ProcessProc; try {/ start the external program / / Proc=System.Diagnostics.Process.Start (Info) } catch (System.ComponentModel.Win32Exceptione) {Console.WriteLine (\ "the system cannot find the specified program file. \\ r {0}\ ", e); return;} / / print out the start execution time of the external program Console.WriteLine (\" start execution time of the external program: {0}\ ", Proc.StartTime); / / wait 3 seconds Proc.WaitForExit (3000) / / if the external program does not stop running, it will be forcibly terminated by if (Proc.HasExited==false) {Console.WriteLine (\ "the main program will forcibly terminate the external program! \ "); Proc.Kill ();} else {Console.WriteLine (\" exit normally by an external program! Console.WriteLine (\ "end run time of external program: {0}\", Proc.ExitTime); Console.WriteLine (\ "return value of external program at the end of running: {0}\", Proc.ExitCode);}} "how to use notepad for calling C#" is introduced here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report