I am new to C # programming. I would like the application to contain 1 text box and 1 submit button to execute the batch file.
The file is d: \ XMLupdate.bat, but the program adds a number on the command line to a file, for example, d: \ XMLupdate.bat 10 or d: \ XMLupdate.bat 15
Another thing is that the submission must be confirmed either 1 -999, or ALL
In the Java method:
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);
}
else{
try{
int boxNumber = Integer.parseInt(jTextField1.getText());
if((boxNumber > 0) && boxNumber < 1000)
{
String arguments = jTextField1.getText();
String command = "CMD /C start d:/XMLupdate.bat " + arguments;
Runtime rt = Runtime.getRuntime();
rt.exec(command);
}
else{
JOptionPane.showMessageDialog(null, "Invalid value entered.");
}
}catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Invalid value entered.");
}
}
However, the machine cannot install the JVM. So I have to build it in exe. My programming language is C #:
Here is the source code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (!(textBox1.Text.Equals("")))
{
if (textBox1.Text.Equals("ALL"))
{
try
{
Process p = new Process();
p.StartInfo.FileName = "CMD.exe";
p.StartInfo.WorkingDirectory = "c:\temp";
p.StartInfo.Arguments = "xmlupdate.bat" + int.Parse(textBox1.Text);
p.Start();
p.WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine("Exception Occurred :{0},{1}", ex.Message, ex.StackTrace.ToString());
MessageBox.Show("Invalid value entered");
}
}
}
}
private void textBox1_TextChanged(object sender, CancelEventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
try
{
int numberEntered = int.Parse(textBox1.Text);
if (numberEntered < 1 || numberEntered > 10)
{
}
}
catch (FormatException)
{
MessageBox.Show("You need to enter a number between 1 and 999");
}
}
}
My main question is about the process method, can I do it this way? thank
source
share