Question Use variable from textbox and run command line

jamms

Member
Joined
Dec 21, 2014
Messages
7
Programming Experience
Beginner
Hi guys.. I'm having so many issues with this.

What I need to do is:
1. Have a form with:
A: 1 button
B: 1 text box

When I click on the button I should be able to get this in a command prompt: "livestreamer (string from textbox) best"

I've tried:
Process.start ("cmd","/k "livestreamer" & Textbox1.Text & "base")

So this "works", but I get: "livestreamer stringbase"
So string and "base" are together. No space.

I've tried using ("cmd","/k "livestreamer" & Textbox1.Text " & """" & "base")
but it's still together.

I've also tried

Dim TestString As String
TestString = Space(1)

Process.start ("cmd","/k "livestreamer" & Textbox1.Text & Space(1) & "base")
But I still get nothing.
This is driving me crazy.

Can anyone help me with this code?
Thanks
 
Um, if you want a space then the logical thing to do is to put a space in. Instead of this:
VB.NET:
& "base"
use this:
VB.NET:
& " base"
Fairly obvious I would have thought. I would recommend using String.Format to avoid confusion that concatenating multiple Strings can cause. I assume that the actual commandline you want to execute is:
VB.NET:
/k "livestreamer xxxxx base"
In that case, your code could and probably should look like this:
Process.Start("cmd",
              String.Format("/k ""livestreamer {0} base""",
                            TextBox1.Text))
By using String.Format you remove the clutter caused by lots of ampersands. Also notice the escaped double quotes inside the literal String, which is how you include a double quote.
 
Hi jmcilhinney

If I do
, I get a win32 unhandled exception error.

If I try the code you gave me, "base" is not passed as a parameter, but instead a "continuation" of xxxxxxx.

/k "livestreamer xxxxx base"

For example:
livestreamer will try to look for the url:
"http://www.domain.com base"
and not
"http://www.domain.com" base

Hope that makes sense.
 
Last edited:
Hi jmcilhinney

If I do , I get a win32 unhandled exception error.

If I try the code you gave me, "base" is not passed as a parameter, but instead a "continuation" of xxxxxxx.



For example:
livestreamer will try to look for the url:
and not

Hope that makes sense.
So is livestreamer the application that you actually want to run? If so then run it instead of cmd:
Process.Start("livestreamer", TextBox1.Text & " base")
Assuming TextBox1 contains "http://www.domain.com" then that is equivalent to typing into a console window:
VB.NET:
livestreamer http://www.domain.com base
 
Yes, livestreamer is the application I want to run.
I tried that code, but it's the "error" I've been getting... "best" doesn't append to the command line.
Note, it was "best", not "base".. typo.

here's a screenshot.
Capture.PNG


As you can see, there is nothing after the URL.
This is driving me nuts.
 
Oh, I get it.. I think.
So if I do this in VB, I don't actually see the command line that is being used in the command prompt.
That's why I wasn't seeing "best", because it's not actually showing the command, just the rest of the output.
Anyway to enable that so I can actually see if it's correct?


EDIT:

Ok, I don't know what I did but it's working.
If you check the caption of the window, the whole thing is there as it should be.

capture3.PNG


Anyways, I think this is it.
Many thanks JM!
 
Last edited:
Back
Top