I run exe from my asp.net with JavaScript using ActiveXObject. It runs successfully, except parameters:
function CallEXE() {
var oShell = new ActiveXObject("Shell.Application");
var prog = "C:\\Users\\admin\\Desktop\\myCustom.exe";
oShell.ShellExecute(prog,"customer name fullname","","open","1");
}
Example, I pass that like parameters,[1] customer name,[2] fullname, but after space character, Javascript perceive different parameter.
How can I fix?
ShellExecute takes the 2nd parameter to be a string that represents all the arguments and processes these using normal shell processing rules: spaces and quotes, in particular.
oShell.ShellExecute(prog,"customer name fullname",...)
In this case the 3 parameters that are passed are customer, name, fullname
oShell.ShellExecute(prog,"customer 'a name with spaces' fullname",...)
As corrected/noted by Remy Lebeau - TeamB, double-quotes can be used to defined argument boundaries:
oShell.ShellExecute(prog,'customer "a name with spaces" fullname',...)
In this case the 3 parameters that are passed are customer, a name with spaces, fullname
That is, think of how you would call myCustom.exe from the command-prompt. It's the same thing when using ShellExecute.
Happy coding.
Try escaping your spaces with a backslash. The cmd.exe cd command does this, maybe you'll get lucky and it'll work here as well...
oShell.ShellExecute(prog,"customer a\ name\ with\ spaces fullname", ...)
Related
I am trying to remove a file extension using parameter expansion. e.g. given a filename of 123.sh, return 123.
If I store the pattern, ".*" in a variable, it does not work —${filename%$suffix} does not work.
If I specify the pattern literally, it does — ${filename%.*}
What am I doing wrong?
In the expansion ${filename%$suffix}, the value of $suffix is substituted literally. To have it be substitute as a pattern instead, you will need to use glob substitution: ${filename%$~suffix}
However, none of this is necessary for what you're trying to do. To remove the extension from a filename, you can simply use the r modifier:
❯ filename="123.sh"
❯ print $filename:r
123
(Note: This is a successor question to my posting zsh: Command substitution and proper quoting , but now with an additional complication).
I have a function _iwpath_helper, which outputs to stdout a path, which possibly contains spaces. For the sake of this discussion, let's assume that _iwpath_helper always returns a constant text, for instance
function _iwpath_helper
{
echo "home/rovf/my directory with spaces"
}
I also have a function quote_stripped expects one parameter and if this parameter is surrounded by quotes, it removes them and returns the remaining text. If the parameter is not surrounded by quotes, it returns it unchanged. Here is its definition:
function quote_stripped
{
echo ${1//[\"\']/}
}
Now I combine both functions in the following way:
target=$(quote_stripped "${(q)$(_iwpath_helper)}")
(Of course, 'quote_stripped' would be unnecessary in this toy example, because _iwpath_helper doesn't return a quote-delimited path here, but in the real application, it sometimes does).
The problem now is that the variable target contains a real backslash character, i.e. if I do a
echo +++$target+++
I see
+++home/rovf/my\ directory\ with\ spaces
and if I try to
cd $target
I get on my system the error message, that the directory
home/rovf/my/ directory/ with/ spaces
would not exist.
(In case you are wondering where the forward slashes come from: I'm running on Cygwin, and I guess that the cd command just interprets backslashes as forward slashes in this case, to accomodate better for the Windows environment).
I guess the backslashes, which physically appear in the variable target are caused by the (q) expansion flag which I apply to $(_iwpath_helper). My problem is now that I can not simply drop the (q), because without it, the function quote_stripped would get on parameter $1 only the first part of the string, up to the first space (/home/rovf/my).
How can I write this correctly?
I think you just want to avoid trying to strip quotes manually, and use the (Q) expansion flag. Compare:
% v="a b c d"
% echo "$v"
a b c d
% echo "${(q)v}"
a\ b\ c\ d
% echo "${(Q)${(q)v}}"
a b c d
chepner was right: The way I tried to unquote the string was silly (I was thinking too much in a "Bourne Shell way"), and I should have used the (Q) flag.
Here is my solution:
target="${(Q)$(_iwpath_helper)}"
No need for the quote_stripped function anymore....
Is it possible to disable Command Substitution in Bash?
I want to pass a string containing several backticks characters as command-line argument to a program, without trailing backslashs or quoting the string.
Thank you.
I assume there is a misconception which grounds your question. Quoting is most likely the solution to your situation. But maybe you haven't found the right way of quoting yet or similar.
If your dangerous string shall be verbatim (without quoting or escaping) in the source code, you can put it in a separate file and read it from there:
dangerous_string=$(cat dangerous_string_file.txt)
If it shall be passed without interpretation to a command, use the double quotes to prevent interpretation:
my_command "$dangerous_string"
If you have to pass it to a command which needs to receive a quoted version of your string because it is known to carelessly pass the string without using sth like the double quotes to prevent interpretation, you can always use printf to get a quoted version:
quoted_dangerous_string=$(printf "%q" "$dangerous_string")
careless_command "$quoted_dangerous_string"
If all these options do not help in your situation, please explain in more detail where your problem lies.
I found the technique below in another StackOverflow issue. It gets the proper "Program Files" directory name, whether the file runs on 32 or 64-bit version of Windows.
How can I get around the problem below. If I don't put double quotes around %programfiles% I get an error on the set.
set BTDFProgFiles=%programfiles(x86)%
if %BTDFProgFiles%=="" set BTDFProgFiles=%programfiles%
echo BTDFProgFiles=%BTDFProgFiles%
%BTDFMSBuildPath% "%BTDFProgFiles%\FRB.EC.Common\%2\Deployment\FRB.EC.Common.BizTalk.Deployment.btdfproj" etc...
If I put double quotes there, the SET statements work, but then the parm to the build program shows with two parms:
set BTDFProgFiles="%programfiles(x86)%"
if %BTDFProgFiles%=="" set BTDFProgFiles="%programfiles%"
echo BTDFProgFiles=%BTDFProgFiles%
%BTDFMSBuildPath% "%BTDFProgFiles%\FRB.EC.Common\%2\Deployment\FRB.EC.Common.BizTalk.Deployment.btdfproj" etc...
Interpreted as:
"C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBu
ild.exe" "C:\Program Files"\FRB.EC.BookTransfer\1.1\Deployment\FRB.EC.BookTransf
er.BizTalk.Deployment.btdfproj" etc...
MSBuild thinks that I'm trying to pass more than one project.;
MSBUILD: Error MSB1008: Only one projet can be specified.
You should use quotes, but in a slightly other way.
set var="my quoted string" sets var to "my quoted string"
set "var=my quoted string" sets var to my quoted string
The second method can quotes string without adding the quotes.
And to echo strings in a secure way without quotes you could use the delayed expansion.
So your code should be changed to
setlocal EnableDelayedExpansion
set "BTDFProgFiles=%programfiles(x86)%"
if "%BTDFProgFiles%"=="" set "BTDFProgFiles=%programfiles%"
echo BTDFProgFiles=!BTDFProgFiles!
"%BTDFMSBuildPath%" "%BTDFProgFiles%\FRB.EC.Common\%2\Deployment\FRB.EC.Common.BizTalk.Deployment.btdfproj"
i am using this to create a new folder
System.IO.Directory.CreateDirectory(#" + somevariable);
the thing is that when i enter the folder c:\newfolder\newfolder in the textbox and is trying to recieve the value up in the controller it is replaced with double slash( \) c:\\newfolder\\newfolder. how would i prevent \ quotes from coming in the path
Secondly the string.replace is also not working for replacing \ with \\
string strText = OrganMeta.vcr_MetaValue;
string gf = strText.Replace("\\", #"\");
"\\" is equivalent to a string of one character, a backslash.
#"\" is also equivalent to a single character, a backslash.
so your Replace method is replacing one form of a backslash with a different form.
try this:
string gf = strText.Replace( #"\\", #"\" );
OR
string gf = strText.Replace( "\\\\", "\\" );
as far as the folder thing goes, Andy is right, it will show a double-backslash in the IDE when in fact there is only one in the string. is there an error when Directory.CreateDirectory() is called? or is the folder created?
Are you sure it's replaced it with \\? If you hover over the variable it will appear to have \\ where there should be a single \ but if you view it in the text visualizer it will show correctly.
Not sure what you mean by string.replace is not working...?? Can you give an example of the code that's not working?
Slashes don't get doubled between the form submit and your controller action.
It's far more likely that you're viewing the result in the debugger or another context that shows two slashes to allow you to distinguish between escaped characters (\n) and a literal slash ().
Write the string to the debug window to verify this.
System.Diagnostics.Debug.WriteLine("SomeText");