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"
Related
I need to append date/time to some test log files generated multiple times in a day. Some suggest doing it like:
set CUR_YYYY=%date:~10,4%
set CUR_MM=%date:~4,2%
set CUR_DD=%date:~7,2%
set CUR_NN=%time:~3,2%
set CUR_SS=%time:~6,2%
set CUR_MS=%time:~9,2%
set SUBFILENAME=%CUR_YYYY%%CUR_MM%%CUR_DD%-%CUR_HH%%CUR_NN%%CUR_SS%
And then concatenate them together but I feel it's just not right. I wonder if there is a better or more concise way of doing it? I imagine there would be a simple solution because the need is quite common.
Thanks!
Well, first of all, data/time formatting is actually a big thing in any programming languages. Just look at the long list of ToString() methods in C# DateTime class, for example, will give you an idea what it is like.
For your particular task, assuming that your locale date using "-" and your locale time using ":" as separators (you can echo date/time to verify:)
echo %date% %time%
If you are not picky, the simplest way to generate a file name is below, and you may replace the '-' and ':' characters according to your own locale, which will give you a valid file name in most systems.
echo "testResult_%date:-=%_%time::=%.xml"
"testResult_20220409_ 84841.28.xml"
If you want only alphanumeric characters in your naming, then probably a cleaner set of commands:
set shortTime=%time:~0,8% ##eliminate the milliseconds in time string
set shortTime=%shortTime: =0% ##replace empty space with zero in morning hours
echo testResult_%date:-=%_%shortTime::=%.xml ##replace '-' and ':' with nothing
That should give you something like
testResult_20220409_084841.xml
However, if you need to deal with application globalization, it's always best to format date/time to a predefined string format using something like PowerShell (on Windows) as the first step. It will then make any subsequent string manipulations easier.
powershell get-date -format "{dd-MM-yyyy_HH:mm:ss}"
When dealing with timestamps you can retrieve the date as I show here on this demo shell file (using bash):
#!/bin/bash
#gets the current timestamp
current_time=$(date "+%Y%m%d-%H%M%S")
echo "Current Time : $current_time"
#crafts the new filename appending $current_time to the original filename
original_filename="filename.log"
new_fileName=$original_filename.$current_time
echo "New FileName: " "$new_fileName"
#renames the file
#mv $original_filename $new_fileName
Situation.. I have two tags defined, then I try to output them to the console. What comes out seems to be similar to an array, but I'd like to remove the formatting and just have the actual words outputted.
Here's what I currently have:
[Tags] ready ver10
Log To Console \n#{TEST TAGS}
And the result is
['ready', 'ver10']
So, how would I chuck the [', the ', ' and the '], thus only retaining the words ready and ver10?
Note: I was getting [u'ready', u'ver10'] - but once I got some advice to make sure I was running Python3 RobotFramework - after uninstalling robotframework via pip, and now only having robotframework installed via pip3, the u has vanished. That's great!
There are several ways to do it. For example, you could use a loop, or you could convert the list to a string before calling log to console
Using a loop.
Since the data is a list, it's easy to iterate over the list:
FOR ${tag} IN #{Test Tags}
log to console ${tag}
END
Converting to a string
You can use the evaluate keyword to convert the list to a string of values separated by a newline. Note: you have to use two backslashes in the call to evaluate since both robot and python use the backslash as an escape character. So, the first backslash escapes the second so that python will see \n and convert it to a newline.
${tags}= evaluate "\\n".join($test_tags)
log to console \n${tags}
I downloaded module Metanet 0.6.2 and ran by Scilab
atomsInstall
After that i ran
`atomsLoad('metanet')`
but it shows
atomsLoad: An error occurred while loading 'metanet-0.6.2':
error(msprintf(gettext('%s module required."),'graph'));
^^
Error: Heterogeneous string detected, starting with ' and ending with ".
at line 335 of function atomsLoad ( D:\Program Files\scilab-6.0.1\modules\atoms\macros\atomsLoad.sci line 351 )
Why did it happen so?
It turns out that the metanet module is not supported by Scilab 6.0.1 yet. I had to install version 5.5.2.
Unfortunately, both the question and the accepted answer here on this page are very vague and misleading. Ideally, this kind of post should be blocked / down-voted, but I will try to answer it as much as I can.
Firstly when you want to run a Scilab command you do not put it in quotation marks, unless you want to use execstr command. However, the characters you have used are not quotations but backticks! I'm not sure why you have done that.
Secondly, the error:
Error: Heterogeneous string detected, starting with ' and ending with "
happens when a double quotation is used inside the single quotation or vice versa:
"This is a' string"
'this is a" string'
to solve the issue you should change the above strings to
"This is a'' string"
'this is a'" string'
basically adding one single quotation before any of the ' and " characters to turn them into literal ' and ".
bonus point if you want to pass a string to Tcl use curly brackets
TCL_EvalStr("set myVar {Hello World!}")
or
TCL_EvalStr("set myVar '"Hello World!'"")
but for PowerShell
powershell('$myVar= ''Hello World!''')
or
powershell("$myVar= ''Hello World!''")
(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....
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", ...)