How to add some parameters with spaces with process.start - vb.net

i just want to know it there is a way to pass some parameters with process start. I know it can be done with some spaces, but i want to send an adress and full name, both of them have their own spaces, and i need to send them as just 1 parameter.

How would you do it if you were typing the commandline into a console window? You'd wrap each parameter in double quotes, right? It is exactly the same when using Process.Start. In VB.NET, you denote a literal double quote with two double quotes in a String, e.g.
Process.Start("myApp.exe", "firstParam ""second param"" thirdParam")
That would be equivalent to typing this into a console window:
myApp.exe firstParam "second param" thirdParam

Related

Split a NSString to multiple commandline arguments

I am getting a commandline string in my application and I am trying to run the same as an NSTask. I can convert it as a C-String and run it using system.
system([commandlineStr cStringUsingEncoding:NSUTF8StringEncoding]);
But I prefer using NSTask instead. For running as NSTask, I need to split the string as command and an array of arguments. Splitting with space doesn't work since there could be arguments with space in between. Currently they are either escaped or quoted. For eg:
cp "~/File with spaces" ~/Folder\ with\ spaces
Is there a built in way to split the string to multiple arguments or write a custom parsing logic for the same.
The format you are trying to parse is the shell command line, there is a program which is rather good at that - the shell. If you did choose to parse it yourself your job would not be finished - you would still have to locate the program to run. The shell does that by taking the command name, cp in your example, and searching for a matching program using a set of paths. To copy this you would have to perform the same search.
There is a much easier way, the shell it itself a program you can invoke with NSTask, and the shell had an option, -c, which takes a single string as argument and parses and execute that string value as a command line. So you can use NSTask, pass the first argument as #"-c", and the second as the string you have. This will handle everything for you - spaces, escapes, pipes, redirection, et al.
HTH

Sending an argument to batch file with spaces. VB

I am using a VB to run .bat file and to pass arguments to it.
Right now I managed to run it and to send the arguments to it, but ran into a problem. My arguments might contain spaces inside. I was trying to use quotes, but it didn't seem to work as I expected. So what I am doing:
Running this code: System.Diagnostics.Process.Start("C:\Users\XXXXXXX\Desktop\New.bat", """"+data+"""")
where 'data' is the argument I am sending. For testing it contains the value:
Hel loo
Inside the .bat file I have a code, that opens notepad and writes the argument inside it. With this code I have managed to pass the argument as one with spaces, but the result is:
"Hel loo"
Any ideas how to get rid of the quotes on each side, while still passing the argument as one with spaces?
I cannot escape them or replace with another symbol. This solution needs to pass the argument as one with spaces inside. Is this possible? The program I am working with is not important.
EDIT
This is the content of the .bat file:
set directory_Rexe="C:\Users\XXXXXXX\Desktop\testBat.txt"
set var=%1
echo %var%>%directory_Rexe%
%directory_Rexe%
You have three options here:
Use %~1, which will strip the quotes.
Don't care about putting everything into argument 1 and quoting and use %* instead. You mentioned not wanting that, though.
Don't pass the string as an argument, but as an environment variable instead. This also helps a lot when you have a number of characters in it that need to be escaped.
All options require you to change the batch file, though.
I'd also question the need for a batch file when you have a perfectly capable programming language already at your fingertips. Writing text to a file should actually be easier from VB.

Escaping double quotes in TF2 scripting

In TF2 scripting, there is a simple command, echo. This simply logs a message to the console. It can be used with or without double quotes. However, I want to be able to log something to the console involving double quotes--say, the string He said, "nope.". In conventional programming, one would escape the quotes, as so:
echo "He said, \"nope.\""
However, in the TF2 console, this writes:
He said, \ nope.\
Is there a way to use quotes in echo and related commands? (E.g. say)
It's not possible to output double quotes using echo or say, only single quotes. (source) (In fact whenever you type double quotes into regular chat they're automatically changed into single quotes. I don't know why this limitation exists, I'd have to dig around.)
I know this is a very old thread, but in case anyone else is trying to find a fix for this and found this post, let me provide an example of how to use single quotes. I had an alias for switching crosshairs, as such:
alias "default" "cl_crosshair_blue 255; cl_crosshair_red 255; cl_crosshair_green 0; cl_crosshair_file "" "
This is to change the color of my crosshair, but more importantly, reset my crosshair to the "None" in options, letting the crosshair change depending on weapon, as I like most of the default crosshairs- but it would fail at the quotation mark immediately after "file", simply changing the colors and nothing more.
Using single quotes fixes this. Using ALT+0145 and ALT+0146 gives you the starting and ending single quotes (respectively) that you need. Replacing those two double quotes after "file" with the single quotes made the command work as intended.
alias "default" "cl_crosshair_blue 255; cl_crosshair_red 255; cl_crosshair_green 0; cl_crosshair_file ‘’ "
So anytime you absolutely need to use a set quotation marks twice in a command, just use single quotes.

Does mIRC Scripting have an escape character?

I'm trying to write a simple multi-line Alias that says several predefined strings of characters in mIRC. The problem is that the strings can contain:
{
}
|
which are all used in the scripting language to group sections of code/commands. So I was wondering if there was an escape character I could use.
In lack of that, is there a method, or alternative way to be able to "say" multiple lines of these strings, so that this:
alias test1 {
/msg # samplestring}contains_chars|
/msg # _that|break_continuity}{
}
Outputs this on typing /test1 on a channel:
<MyName> samplestring}contains_chars|
<MyName> _that|break_continuity}{
It doesn't have to use the /msg command specifically, either, as long as the output is the same.
So basically:
Is there an escape character of sorts I can use to differentiate code from a string in mIRC scripting?
Is there a way to tell a script to evaluate all characters in a string as a literal? Think " " quotes in languages like Java.
Is the above even possible using only mIRC scripting?
"In lack of that, is there a method, or alternative way to be able to "say" multiple lines of these strings, so that this:..."
I think you have to have to use msg # every time when you want to message a channel. Alterativelty you can use the /say command to message the active window.
Regarding the other 3 questions:
Yes, for example you can use $chr(123) instead of a {, $chr(125) instead of a } and $chr(124) instead of a | (pipe). For a full list of numbers you can go to http://www.atwebresults.com/ascii-codes.php?type=2. The code for a dot is 46 so $chr(46) will represent a dot.
I don't think there is any 'simple' way to do this. To print identifiers as plain text you have to add a ! after the $. For example '$!time' will return the plain text '$time' as $time will return the actual value of $time.
Yes.

How do you pass SOME_LIB="-lmylib -lmylib2" in a BUILD_COMMAND for ExternalProject_Add()?

I'm trying to pass a quoted string through BUILD_COMMAND in ExternalProject_Add() and every way I try it's getting mangled. The code is this:
set (mylibs "-lmylib -lmylib2")
ExternalProject_Add(Foo
URL http://foo
BUILD_COMMAND make SOME_LIB=${mylibs}
BUILD_IN_SOURCE 1
...)
I've tried using backslash quotes, double quotes, inlining the whole thing, but every time, either the whole SOME_LIB=... part gets quoted or my injected quotes get escaped. Is it not possible to get quotes through to the command line so they just cover the parameters?
Even though I'm unable to get the resulting make call to look like make SOMELIB="-lmylib -lmylib2", you can make it call make "SOMELIB=-lmylib -lmylib2" which seems to do the same thing.
Have you tried quoting like this?
ExternalProject_Add(
...
BUILD_COMMAND make "SOME_LIB=\"${mylibs}\""
...
)
The outer pair of double quotes says "this is all one argument here", and the inner pair of escaped double quotes says "these are embedded IN the argument".
It may need extra escaping, though. I haven't tried this and I'm not certain it will work. But there should be a way to add escape characters until it does work... Or, worst case, you could write out a script file (bash .sh or batch .bat) that has proper shell syntax for calling make like you want it and then invoke executing the script file as the BUILD_COMMAND.