psake calling msdeploy.cmd with parameter containing an ampersand - msdeploy

I have a psake script to manage my deployments, the process is as follows:
Compile & run tests
Generate a deployment package using msbuild
Check to see if we are deploying internally or externally
If internal, execute the generated cmd file
if external, prompt for username and password and execute the generated cmd file with the username and password as parameters
I'm executing msdeploy in the following manner when deploying externally:
exec { & $deploy_cmd /Y /M:$msdeploy_url /U:$user /P:$pwd /A:NTLM }
When the password contains an ampersand (&) then the cmd file, I assume, when assigning the parameter to a variable assigns the portion of the password before the & and tries to execute the portion afterwards. Which is bat file behaviour (& are used to separate commands).
I've tried escaping the password with the caret (^) during the prompt for the password, but that didn't work.
Other than changing the password, are there any other alternatives?

Because the cmd file is parsing the parameters and then passing them again as raw strings the only way I've gotten a | character to work in a password is to triple escaped it with ^^^ before some of the special characters. I'm assuming & will work similarly. Or you can just escape all characters in the password:
$pwd = $pwd -replace '.','^^^$&'

Related

Makefile wildcard function evaluates to true against empty string

Using GNU Make 4.2.1
I'm writing a Makefile, and I want to use a conditional statement to have make check whether it is on a specific remote server or not. I'd like to do this using the unix HOSTNAME environment variable. I also want it to run regardless of subdomain, so I use the make wildcard function.
ifeq ($(wildcard *.remote.server.com),$(HOSTNAME))
echo "ON REMOTE SERVER"
else
echo "NOT ON REMOTE SERVER"
endif
This looks like it would work, but on my local machine the HOSTNAME environment variable is not set and the ifeq test evaluates to true and prints ON REMOTE SERVER.
This doesn't make sense to me; *.remote.server.com is being compared to an empty string and should evaluate false and print NOT ON REMOTE SERVER.
Am I missing something about either unix environment variables, wildcard, or make conditionals, or all three?
Edit: Problem resolved. Learned that this is not the spot to use the wildcard function. Instead, used something similar to the following line
ifeq "$(shell hostname | sed -e 's/.*.remote.server.com/remote.server.com/')" "remote.server.com"
Based on this response:
How to use bash regex inside Makefile Target
You could just print the values of these things to see what they are. Something like $(info wildcard='$(wildcard *.remote.server.com)' hostname='$(HOSTNAME)')? The reason for this behavior depends entirely on your local system, which we do not have access to.
However, I don't see why you say that *.remote.server.com is being compared to an empty string. You've written $(wildcard *.remote.server.com) and presumably you don't have a file that matched the glob *.remote.server.com, which means the wildcard function expands to the empty string.
I think you might be confused about what the wildcard function does: what did you expect it to do? It has nothing whatever to do with hostnames.

Null character in input file

We are migrating informatica from windows to Unix as a result when I was running workflow in windows which consists of 10 sessions, getting succeeded.
But same workflow (code) has been migrated to unix Environment. However workflow getting failed due to NULL character in input file.
EX:
FR_3085: 513th character is a null character, which is not allowed in a text input file
Don't know where went wrong, as other 9 sessions(out of 10) getting succeeded.
You can follow 2 approaches in this case :
Replace the null character in the file using SED or any other Linux commad/method before workflow run.
User given custom properties at your session/workflow.
https://kb.informatica.com/solution/6/Pages/20698.aspx
Thanks
If you are on RHL sometimes the conversion from Window to Shell script will bring Unicode characters.
Try running dos2unix filename.txt command and then convert the file format to Unix. After doing this run the workflow.
Also you can check whether the file has Unicode or not by running cat -v filename.txt

Passing variables to sshexec command resource file in ANT

I have created a large script to be passed to an sshexec commandResource in ant as follows.
<sshexec host="${host.server}"
username="${username}"
password="${oracle.password}"
commandResource="path-to-file/script.txt"
/>
This is working as intended.
There are several lines that will get executed on the server in that script. The contents of the script.txt file is as follows :
/script/compile_objects.sh /path-to-code/ login password
/script/compile_code.sh /path-to-code/ login password
However, I would prefer to not store the login and password as clear text in the script.txt file. Is it possible to pass parameters to each line of the command resource. I'm aware that each line in the command resource file gets executed in its own shell.
I tried string replacement from a property in the Ant script, but it failed with a bad substitution error like so. Is there another way to do this?
<property name="oracle.password" value="thepassword"/>
and then in the script file, alter to:
/script/compile_objects.sh /path-to-code/ login ${oracle.password}
/script/compile_code.sh /path-to-code/ login ${oracle.password}
This type of replacement works when using the command feature, but seems to fail when using commandResource.
Edit :
I am using Apache Ant 1.9.4
and jsch-0.1.54.jar

How do I open a document from R?

I want to open a file from within R.
I can launch the software (graphpad prism) with the following:
system2("C:/Program Files (x86)/GraphPad/Prism 7/prism.exe")
I expected this to open my prism file as if I were double clicking on it or running it from cmd, but it didn't:
system2("H:/Graphs/Shell/Templates/NASH4_Standard.pzfx")
I am receiving the message:
Warning message: running command
'H:/Graphs/Shell/Templates/NASH4_Standard.pzfx' had status 127
I see that this is not an error but just a warning. Am I unintentionally "shelling" the document in the background? How would I make sure it pops up as a window?
Status 127 was addressed here, but for launching the software, not opening the document with it.
In Windows environments, you need to call a command line interpreter like CMD prompt or PowerShell. Also, any file path that has spaces needs to be enclosed in double quotes above the quotes needed in R for string literals (the case for your .exe not specific file).
With system() send entire command in one string:
system('cmd /c "H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"')
# POWER SHELL REQUIRES MORE QUOTE ESCAPING (ONLY ONE PAIR W/O SPACES)
system('powershell & """H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"""')
With system2() use the args parameter:
# FILES
system2('cmd', args=c('/c', '"H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"'))
system2('powershell', args=c(' & """H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"""'))
# EXECUTABLES
system2('cmd', args=c('/c', '"C:/Program Files (x86)/GraphPad/Prism 7/prism.exe"'))
system2('powershell', args=c(' & """C:/Program Files (x86)/GraphPad/Prism 7/prism.exe"""'))
shell.exec("C:/Program Files (x86)/GraphPad/Prism 7/prism.exe")
does it work for you ?
ps. and shell.exec("MyWorkbook.xls") open file with default program

What is the use case for this zsh precommand modifier '-'

So in zsh; do this
$ - ls /some/non/existent/directory/blah/blah/blah
gives you
-ls: /some/non/existent/directory/blah/blah/blah: No such file or directory
Documentation:
http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Precommand-Modifiers
What reasonable use case does this actualy have?
From zshmisc(1):
- The command is executed with a `-' prepended to its argv[0]
string.
Invoking a shell with a - prepended to its name (-sh, -bash, -zsh) is an old convention for indicating the shell should start a login session. It's up to the program itself to decide if such an invocation should mean anything. Most programs, like ls, ignore how they are called.

Resources