How to write the xxd command in cmd in windows - windows

I am trying to use xxd command to convert string to hex.
I have typed this command in cmd in windows xxd -p <<< "Hello world".
But I have got this in my cmd
'xxd' is not recognized as an internal or external command, operable program or batch file.
How can I use xxd in cmd in windows?
Thanks.

Use VIM for this
https://ftp.nluug.nl/pub/vim/pc/gvim73_46_s.zip
C:\Program Files (x86)\Vim\vim74>.\xxd -v
Source: https://superuser.com/a/638850

You could use git-bash to do that if you have installed it.

Short answer is you probably can't because it's a UNIX command...
What you can do is use GnuWin32/MinGW/CygWin, which are ports of Linux GNU utilities fro Windows.
Read more about them here:
Difference between GNUWin32 and cygwin

These days the full linux kernel is made available and officially supported by windows via WSL. Once installed, a program like Windows Terminal can be used to execute linux commands.

See this utility clone.
https://sourceforge.net/projects/xxd-for-windows/
The operation is similar. To see in hexadecimnal use "xxd file.txt", to see in binary use "xxd -b file.txt".

Related

jq crashing under Windows 10 using any command

I've used jq on Mac/Unix successfully for several years and have now been asked to port a project from Mac to Windows.
My problem is that I am unable to run any command in jq under Windows with the .json files that work perfectly on the Mac.
This includes the simplest command:
jq -r . /path/to/json.json
All commands cause a crash of jq. I'm running Windows 10 Pro.
What I've tried:
-Installing jq using chocolatey as well as downloading the precompiled 32-bit and 64-bit binaries directly.
-Using a standard command prompt, an elevated command prompt and PowerShell.
The .json files all have UTF-8 encoding without BOM and I've tried them with both Windows and Unix line endings. jq crashes regardless.
Can anyone please provide any guidance as to why a simple port to Windows would be so problematic, or maybe some simple issue I am overlooking?
Thanks
This includes the simplest command:
jq -r . /path/to/json.json
To ascertain the nature of the problem, it would probably be better to start with an even simpler command, such as:
jq -n .
If that fails, maybe there is a 32-bit/64-bit mismatch.
Also, when specifying pathnames, you will have to use Windows conventions.
Please note that jq 1.5 cannot handle long Windows pathnames. You can obtain a more recent version of jq pre-compiled for Windows from Appveyor, as explained at
https://github.com/stedolan/jq/wiki/Installation#windows-using-appveyor

How do I pass an arbitrary command line argument to a native Windows program from a MinGW shell?

How do I pass an arbitrary command line argument to a native Windows program from a MinGW shell?
I would like a general solution, but a solution that works for any valid Windows filename would be acceptable.
That shell is Bash. Cygwin/MSYS2 Bash can accept Windows paths, but you need to
deal with spaces and backslashes. Regarding backslashes:
program 'C:\alfa.txt'
program C:\\alfa.txt
program C:/alfa.txt
Regarding spaces:
program 'C:\alfa bravo.txt'
program C:\\alfa\ bravo.txt
program C:/alfa\ bravo.txt
As you can see, if you are supplying Windows paths, this is pretty straight
forward. The only issue you might get is if you are trying to supply Bash paths
to a Windows native program:
program /tmp/alfa.txt
Windows native programs have no concept of /tmp or even /. Cygwin/MSYS2 have
cygpath to assist in converting these paths:
program $(cygpath -m /tmp/alfa.txt)
program "$(cygpath -w /tmp/alfa.txt)"
program "$(cygpath -m '/tmp/alfa bravo.txt')"
program "$(cygpath -m /tmp/alfa\ bravo.txt)"
program "$(cygpath -w '/tmp/alfa bravo.txt')"
program "$(cygpath -w /tmp/alfa\ bravo.txt)"
Side note: MinGW is an old project. You should be using Cygwin or MSYS2.

Command prompt isn't integrating anything

I installed amazonCLI, as well as Cygwin, and changed the Path env variable to:
%SystemRoot%\System32\Wbem;C:\Program Files\Prio;C:\Program
Files\Diskeeper Corporation\ExpressCache\;C:\Program
Files\Amazon\AWSCLI\;C:\cygwin64\bin
When I open the command prompt, first of all it is directly pointing to
C:\Users\Stephane
(which I think is weird). And then when I input something like 'ls', the return error is:
'ls' is not recognized as internal or external command, operable program or batch file
Can you please help me know what I am doing wrong?
Thanks
From the error message you got, it's evident, that you are trying to execute Cygwin's commands from the Windows Console. That's also the reason, why it's executed in your Windows' profile directory instead of the Cygwin's one.
You should read the basics about using the Cygwin first, because it seems you don't know what Cygwin exactly is and how to use it. Maybe you don't need the Cygwin at all, it depends on what you need to accomplish. The is for example GnuWin tool set or UnxUtils, which are just a sets of standalone GNU tools compiled for Windows. Cygwin is more like system than standalone utilities. You can for example execute shell scripts under the Cygwin.
So it depends on your needs. But I simply can't imagine using Windows without Cygwin yet.
You can execute Cygwin's shell from the Windows Console, but I advice you to use MinTTY (which is in directory $CYGWIN_DIR/bin). MinTTY is a terminal emulator, which executes your Cygwin shell (bash by default).
To execute for example bash directly from the Windows Console, just execute $CYGWIN_DIR/bash.exe --login -i.

How to change console code to 1252?

I am trying to use PostgreSQL on Windows 8 using the command line provided by Git Bash so I can run Unix like commands. When accessing Postgres with the following command: psql -U postgres I get:
Warning: Console code page (850) differs from Windows code page (1252)
etc...
in the Windows command tool, I just need to type chcp 1252 before accessing Postgres so the warning doesn't show up. What's the equivalent command in unix/git bash?
I tried to do chcp 1252 or chcp from Git bash but it outputs:
sh.exe": chcp: command not found
Any ideas?
Try "chcp.com 1252".
Git bash doesn't suppose ".com" as a implicit executable postfix.
It can't expand "chcp" to correct executable, so you should type fully "chcp.com".
You're using the Windows psql.exe binary under the msys bash.
This may not work well, as psql.exe is a Win32 binary. It uses stdio, but not the same way bash expects.
You'll want to either use a psql built against msys (not trivial), or use psql under cmd.exe or powershell.

Redirecting output to multiple files and to stdout simultaneously in win XP command line

I would like to redirect the output from a command to a file and to stdout. I am using Windows XP command line.
I realize that there is a command in linux called tee which will do this, but I want this in windows.
The first hit when googling windows tee gives UNIX-style tee utility for Windows
Use tee for windows.
The simple DOS shell doesn't have the ability to do this simultaneously.
Try using:
Windows PowerShell
or
Cygwin
If using tee (one of the various Windows variants) isn't an option and the command isn't long-running or you don't need to do further processing of the output in real time, then
command > file && type file
would do that for you. But only under the mentioned circumstances. You're probably be better off using tee.
PowerShell has tee-object (standard alias tee) if you are using a decent shell.

Resources