I have Problems adding a line feed in a string passed to a command line command. The Syntax is like this:
sometool --modifyfield "Description"="How to add a line feed?"
What I already tried without success:
sometool --modifyfield "Description"="How to add a \n line feed?"
sometool --modifyfield "Description"=$"How to add a \n line feed?"
... and othercombinations using % and ^
...but I always see exactly the text behin the "=" in my Description field.
Is it possible to add a line feed here?
PowerShell can be installed on Windows 7. Is sometool an executable .exe?
powershell -NoProfile -Command "& sometool --modifyfield "Description"="How to add a `n line feed?"
Related
This question seems to be rather simple, but even after searching the web for a couple of hours, I was not able to find a solution...
I have a batch file test.bat
set MY_VARIABLE=%~1
echo %MY_VARIABLE%
The point is that I want to call this programm with a semicolon as input parameter, i.e.,
.\test.bat ";",
from both cmd and Windows PowerShell. While this works fine from cmd, PowerShell does not seem to get anything as an input. Is there any way to make this work for both simultaneously?
This is because of command line syntax. The semicolon is one of multiple delimiters, that split the command line into words: a;b would be interpreted as two separate arguments a (%1) and b (%2).
Therefore, quotes are required. Since Powershell uses quotes for string literals (Powershell does its own re-quoting behind the scenes when passing arguments), you need to include them in the string:
.\test.bat '";"'
# or
.\test.bat "`";`""
Or as #mklement0 pointed out, the stop-parsing symbol --% would also be an option:
.\test.bat --% ";"
Note that this is specific to Powershell syntax.
In CMD, this will suffice:
test.bat ";"
I am trying to run beyond compare via command line.
The command I am using is :
BCompare.exe #"My Config File.txt" "File 1.xml" "File 2.xml"
But this is not working because of spaces in the file Names.
Beyond Compare shows a "file not found" error (as it is looking only for the part of fileName before spaces)
If I compare files without any space in file name, it works.
Since you're running a script but haven't shown that, I suspect you aren't quoting the arguments there properly. The quotes on the command line are going to be stripped as part of the command line processing, so if your script is:
file-report layout:side-by-side %1 %2 output-to:printer
It should actually be
file-report layout:side-by-side "%1" "%2" output-to:printer
Without the extra quotes the variables would be expanded like:
file-report layout:side-by-side File 1.xml File 2.xml output-to:printer
Running Windows 7, configuring a commit hook in my .hgrc file.
The hook calls an external powershell script and passes it a few parameters. When I put all the parameters on one long line, the script receives them just fine. However, when I try to put each parameter on its own line, the hook can't figure out that they are all part of the same call to my external script.
[hooks]
commit.working_one_liner = PowerShell.exe -ExecutionPolicy Bypass -File .\MyScript.ps1 -hg %HG% -updatedToChangeset %HG_NODE% -dbName 'Test'
commit.multi_line_hook_not_working = PowerShell.exe
-ExecutionPolicy Bypass
-File .\MyScript.ps1
-hg %HG%
-updatedToChangeset %HG_NODE%
-dbName 'Test'
According to the Hg documentation, I should be able to do this:
"A configuration file consists of sections, led by a [section] header and followed by name = value entries (sometimes called configuration keys):
[spam]
eggs=ham
green=
eggs
Each line contains one entry. If the lines that follow are indented, they are treated as continuations of that entry. Leading whitespace is removed from values. Empty lines are skipped. Lines beginning with # or ; are ignored and may be used to provide comments."
Despite indenting, the multi_line_hook seems to ignore everything after the first line. I've tried various escape characters (`, ^, \, etc.) after each new line. Any ideas what I'm missing here?
The example from the documentation only works for the first line to follow and not the rest.
I don't have access to windows at the moment, but on linux I need to use a backslash:
[hooks]
commit.working = echo \
test
I want to open a text file in notepad++ in a particular line number. If I do this in cmdline the command should be:
start notepad++ "F:\Path\test.txt" -n100
And it is working fine from command line. Now I have to do this from tcl. But I can't make this command work with exec. When I try to execute this:
exec "start notepad++ \"F:\Path\test.txt\" -n100"
I am getting this error:
couldn't execute "start notepad++ "F:\Path\test.txt" -n100": no such file or directory.
What am I missing. Please guide.
Similar to this question:
exec {*}[auto_execok start] notepad++ F:/Path/test.txt -n10
First, you need to supply each argument of the command as separate values, instead of a single string/list. Next, to mimic the start command, you would need to use {*}[auto_execok start].
I also used forward slashes instead of backslashes, since you would get a first level substitution and get F:Path est.txt.
EDIT: It escaped me that you could keep the backslashes if you used braces to prevent substitution:
exec {*}[auto_execok start] notepad++ {F:\Path\test.txt} -n10
You can simply surround the entire exec statement in curly braces. Like this:
catch {exec start notepad++.exe f:\Path\test.txt -n10}
I haven't found a perfect solution to this yet. All my execs seem to be different from each other. On windows there are various issues.
Preserving double quotes around filename (or other) arguments.
e.g. in tasklist /fi "pid eq 2060" /nh the quotes are required.
Preserving spaces in filename arguments.
Preserving backslash characters in filename arguments.
[Internally, Windows doesn't care whether pathnames have / or \, but some programs will parse the filename arguments and expect the backslash character].
The following will handle the backslashes and preserve spaces, but will not handle double-quoted arguments. This method is easy to use. You can build up the command line using list and lappend.
set cmd [list notepad]
set fn "C:\\test 1.txt"
lappend cmd $fn
exec {*}$cmd
Using a string variable rather than a list allows preservation of quoted arguments:
set cmd [auto_execok start]
append cmd " notepad"
append cmd " \"C:\\test 1.txt\""
exec {*}$cmd
Note that if you need to supply the full path to the command to be executed, it often needs to be quoted also due to spaces in the pathname:
set cmd "\"C:\\Program Files\\mystuff\\my stuff.exe\" "
I'm very awkward in PowerShell and I use it only at home for my own simple tasks under my Windows XP where no available upgrade to PS2. Next test show that my PowerShell 1.0 use MTA mode by default.
[threading.thread]::CurrentThread.GetApartmentState()
And such call like...
PowerShell.exe –STA c:\scripts\file.ps1
...always fail with error:
Missing expression after unary operator '-'. At line:1 char:2
+ -S <<<< TA c:\scripts\file.ps1
Looks like my PS1 not recognize –STA switch. What I do wrong? Is there any way at all to run my script in STA mode in PS1?
The dash character before STA in your command is "–" Unicode U+2013 "En Dash" where it should be "-" Unicode U+002D "Hyphen-Minus". You can try it with this JavaScript function in your browser console (F12):
function getHex(character) {
return "0x" + character.charCodeAt(0).toString(16);
}
getHex('–'); // 0x2013
getHex('-'); // 0x2d
Perhaps you have copied it from a web page or a PDF or Word document. Try to type the command instead of copy/paste and it will work.
New versions of PowerShell will recognize both characters for dash.
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Sta -File c:\scripts\file.ps1