How to prevent MSYS from converting remote file path for pscp - filepath

I'm using msys2 bash 4.3.26 (i686-pc-msys) on Windows, and recently I find that it breaks my pscp and scp (msys1):
When I run pscp req.py hostname:/home/user/xxx/yyy/:
msys will change the second args to hostname;D:\msys\home\user\xxx\yyy\
and then pscp will report: ssh_init: Host does not exist
my scp which is from msys-1.0 (I once used git-for-windows 1.9) reports ssh: Could not resolve hostnamehostname;d: no address associated with name
This is annoying and I have to open cmd.exe to use pscp. Is there any way to prevent MSYS 2 from convert special args?
I tried wrapping an arg in ' or " and failed
http://www.mingw.org/wiki/Posix_path_conversion is not helpful but disappointing
environment: Windows 10 Insider x64 and msys2 i686
the official scp.exe in the same package of msys2 works well
BTW, this problem only occurs on those .exe files which does not use msys2 DLLs. How this difference is being checked?

MSYS2 converts POSIX-style path names to Windows-style path names when it detects you are running a native Windows program like pscp. These conversions use a lot of heuristics and sometimes they get the wrong answer.
You can inhibit conversions of certain arguments by setting the MSYS2_ARG_CONV_EXCL environment variable as you run the command. It is a list of prefixes of arguments for which MSYS2 should not attempt to convert paths. You could just set the variable to the empty string in order to turn off all conversions. However, you might need the first argument to pscp to be converted since it is a path on your local computer. So you should try running your command like this instead:
MSYS2_ARG_CONV_EXCL=hostname pscp req.py hostname:/home/user/xxx/yyy/

Related

need to find the path for my file (cygwin in Window7)

My apology for the "newbie trouble" that I created for myself & apology for my poor command of computer lingo
I am running a Windows 7 laptop and have a big text file (~4Gb) that I need to find certain string.
Most programs in Windows 7 cannot handle the task (file too big to open in any program in the Microsoft suite), so I downloaded cygwin and tried to grep the specific string.
The problem is
(a) the 4 Gb file is stored in the desktop of my non-admin account.
(b) I assume cygwin runs in the admin account (although I use the desktop cygwin icon to launch the environment). The reason being that under cygwin, I see the handle A#Admin-THINK (running it on a Lenovo Thinkpad laptop)
grep the file of interest results in "No such file or directory"
I tried to find the path of the file (readlink, realpath) but guess the commands were not applicable here?
Also tried /home/A/file or /home/A/desktop/file but it is clear that my random guess fails.
From windows, the file should be in
C:/Users/non_admin/desktop/folder/file
What would be the right path of the file to grep the string using cygwin ?
You can use /cygdrive to access the Windows filesystem. In your case, try
grep foo /cygdrive/c/Users/non_admin/Desktop/folder/file
From windows, you can get the correct file path from the context menu item Copy as path into the copy/paste buffer.
In Cygwin mintty, use
FilePath=<paste>
where <paste> means to use paste from mintty's context menu to make a variable with the value of that path.
Then use
grep <string> $(cygpath -u "$FilePath")
to search the file. The "'s are in case the file name contains spaces.
HTH

run windows command from R

In windows 7 at run prompt, this command succeeds in launching the .exe with the the optional input file "test2.dat"
c:/Program Files (x86)/IEUBKwin1_1 Build11/IEUBKwin32.exe k:/Project/EPA.Pb.IEUBK/batch.io/input/test2.dat
I want to do the same thing from within R.
In R, this command succeeds in launching the same .exe
shell.exec("c:/Program Files (x86)/IEUBKwin1_1 Build11/IEUBKwin32.exe")
But I've been unable to find a solution within R that will launch the .exe with the optional input file. I've looked at shell(), shell.exec() and system() but I could not find the right incantation that will pass the optional input file to the .exe.
Any thoughts?
Typing into the normal cmd.exe-promt a command including spaces as in C:\Program Files (x86)\... does not work:
The Command "C:\Program" could not be found.
Typing in the same command with double quotes does work. E.g.:
"C:\Program Files (x86)\7-Zip\7z" -a ...
To get it to work in R, you can use single quotes (') to mark a R string and double quotes (") for the command itself. Actually, you have the possibility of three different quotes to use (backtick is the third one `, see here for more information). Or you use escapes as mentioned in the answer of #Frank.
system('"C:/Program Files (x86)/IEUBKwin1_1 Build11/IEUBKwin32.exe" k:/Project/EPA.Pb.IEUBK/batch.io/input/test2.dat')
In addition ?system mentions not just to use shell in windows but also system2 as alternative:
...This means that it cannot be assumed that redirection or piping will work in system (redirection sometimes does, but we have seen cases where it stopped working after a Windows security patch), and system2 (or shell) must be used on Windows.
But for me system works totally fine not using piping or redirection.
shell.exec() is used for opening files associated in your OS.
in your case, the shell command should be preferred but you need to take care of spaces in your filenames and mask quotaion marks.
Please try:
shell("\"c:/Program Files (x86)/IEUBKwin1_1 Build11/IEUBKwin32.exe\" k:/Project/EPA.Pb.IEUBK/batch.io/input/test2.dat")

Why am i able to run unix commands on my PC?

How am i able to execute UNIX commands on my PC Command prompt? Note i do not have cygwin installed, although i was going to before i discovered this.
This is a development machine so i have a lot installed on it like ruby, python, git, github, node and so on.
What does this mean? can i use this without cygwin?
Here is a list of programs installed on my PC program list
How am I able to execute UNIX commands on my PC Command prompt?
You can use the where command in a cmd shell to find out the exact location of your Unix commands, for example:
where ls
This assumes, of course, that ls is located somewhere in your current PATH.
The location returned will show you in which directory your Unix commands are installed and may be enough for you to determine how they were installed.
The where command is roughly equivalent to the Unix which command.
By default, the search is done in the current directory and in the
PATH.
Syntax
WHERE [/r Dir] [/q] [/f] [/t] Pattern ...
WHERE [/q] [/f] [/t] [$ENV:Pattern
Source where
Further Reading
An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
where - Locate and display files in a directory tree.
Running Unix commands in windows can be done by having a tool like Cygwin which has those commands.
You can also get many of those commands compiled for windows and then run them using the command with the full path or only the command if the executable is in a path known by adding the paths to the executable files in Windows by :
1) Running in the terminal: PATH %PATH%;C:\<new_path>
2) Creating command aliases like: doskey np=C:\<new_path>\new_command.exe $*. $* is used to be able to transmit parameters

How do I initialize LLVM's external symbolizer?

When compiling with -fsanitize=memory I get WARNING: Trying to symbolize code, but external symbolizer is not initialized! when running the program. How do I initialize the external symbolizer?
I solved my own problem using MSAN_SYMBOLIZER_PATH=$(which llvm-symbolizer-3.4) ./a.out. The problem is that Ubuntu postfixes the version number but the binary doesn't know that. Of course you need to use MSAN instead of ASAN when using the memory sanitizer.
You are supposed to be able to set the ASAN_FILTER environment variable to point at a symbolizer, but I could not get it to work. However, you can redirect stderr into a symbolizer after the fact. You'll still get the warnings about the uninitialized symbolizer, but the filenames and line numbers will be correct.
You can use asan_symbolizer.py as the external symbolizer. After downloading it from that link (to /tmp, for example), invoke your program like so (in bash, for this example):
./myprogram 2>&1 | /tmp/asan_symbolize.py | c++filt
On my Ubuntu system, the issue is that LLVM's tools are installed under /usr/bin with version suffixes (like llvm-symbolizer-4.0), and the sanitizer tools are looking for them without version suffixes.
LLVM also installs its binaries to, e.g., /usr/lib/llvm-4.0/bin; the tools under /usr/bin are actually just symlinks. So an easy solution is to add the appropriate /usr/lib/llvm-*/bin directory to your path when working with sanitizers.
I received such warning when I run program debug version (compiled with -fsanitize=address) on Linux machine that didn't contain clang installation. The problem disappeared after I installed clang from devtoolset.

Console Window Host, always use quotes?

Console Window Host, or conhost.exe allows you to drag a file or folder into a cmd.exe window, instead of typing the path.
If the path contains any spaces then it is wrapped in double quotes, eg
"C:\Program Files"
Problems
Ampersand
If you happen to have a path with & dragging it will fail
cd C:\foo&bar
The system cannot find the path specified.
'bar' is not recognized as an internal or external command, operable program
or batch file.
Bash
If you happen to be using Bash on Windows then any path without a space will
fail.
$ cd C:\Windows\System32
sh: cd: C:WindowsSystem32: No such file or directory
Is there a way to make conhost always apply the quotes to dragged files?
One alternative is to use Tab to complete the path.
I had to edit my ~/.inputrc to add this.
"\t": complete-filename
source: gnu.org/software/bash/manual/bashref
Use mintty
It is the default terminal in Cygwin.
It is also available for MinGW.
It uses Linux like paths when dragging
Adds quotes when necessary.
Note
mintty will not have colors when running native Windows shell apps.
superuser.com/questions/184186
Use Console
It is available for MinGW
It uses Windows paths, but puts quotes on everything
Colors work even with native Windows shell apps
Notes
I considered mintty, but it does not
support colors with native Windows shell apps, ie Git.
superuser.com/questions/184186
Console is nice but it is very slow

Resources