Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
116 views
in Technique[技术] by (71.8m points)

c# - Passing parameters to exe from ini file

I'm writing a program to launch a project. Please tell me how to transfer parameters from such an ini file to exe?

[Data]
User = "Test"
UID = 1234
[Path]
Dir = E:Test
Exe = test.exe

So I try to assign them

   process.StartInfo.FileName = BasePath + "\Loader.exe";
           process.StartInfo.Arguments = Resources.Start;
           process.StartInfo.WorkingDirectory = BasePath;

Please tell me how to implement this? The ini file must be transferred, it does not accept a simple line. Or I am doing something wrong.

question from:https://stackoverflow.com/questions/65642787/passing-parameters-to-exe-from-ini-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If I understand you well, this code should work (replace "Loader.exe" and "inifile.ini" with proper names of your files):

ProcessStartInfo psi = new ProcessStartInfo(BasePath + "\Loader.exe");
psi.Arguments = BasePath + "\inifile.ini";
psi.WorkingDirectory = BasePath;
try
{
    Process p = Process.Start(psi);
}
catch (Exception ex)
{                
    MessageBox.Show("Error:
" + ex.InnerException, "Run Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...