I have a button, and I use Process.Start when clicking it, although I select data from textBox1.Text.
Although this data on textBox1.Text does not come out properly if there are spaces in textBox1.Text
e.g. textBox1.Text = testing_123 works
although textBox1.Text = testing 1 2 3 doesn't work (it will only include "testing")
The code is below:
private void button19_Click(object sender, EventArgs e)
{
Process.Start("test.exe", textBox1.Text);
}
If you want to pass named string arguments containing spaces in between to the python script, you can simply put the text in double quotes.
How do you pass a command line argument with spaces? By enclosing the path (or parts of it) in double quotation marks ( ” ). By adding a caret character ( ^ ) before each space. (This only works in Command Prompt/CMD, and it doesn't seem to work with every command.)
Start(String, String) Starts a process resource by specifying the name of an application and a set of command-line arguments, and associates the resource with a new Process component.
C# Process class provides Start method for launching an exe from code. The Process class is in the System. Diagnostics namespace that has methods to run a .exe file to see any document or a webpage. The Process class provides Start methods for launching another application in the C# Programming.
Simply quote the args like this before passing:
private void button19_Click(object sender, EventArgs e)
{
Process.Start("test.exe", "\"" + textBox1.Text + "\"");
}
Add quotes around your argument string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With