Exposing cmd.exe from zsh - cmd

On windows subsystem for linux, I can acces the native windows comand prompt through
$ cmd.exe [command]
However, when running oh-my-zsh, The cmd.exe api does not seem to be exposed...
$ cmd.exe
zsh: command not found: cmd.exe
How can I expose the cmd.exe api to be available in oh-my-zsh?

Found it!
Just had to set my PATH variable in zsh equal to the one in WSL (no zsh)...

Related

Why is $OSTYPE returning "linux-gnu" on Windows?

Problem
When I run a bash script on Windows:
bash my_script.sh
I get linux-gnu for $OSTYPE inside the script.
Why is this like this?
I assume that i have WSL installed is relevant here.
Tested in PowerShell and CMD.
Git bash is returning msys like expected! Thx #user1934428
Background
I want to start some python scripts from bash, but not inside WSL.
From my command line I reach different python versions on windows, but from inside the bash scripts it is using the one inside WSL (except for GitBash).
You're right, running the bash command in PowerShell or CMD will launch WSL to run your script. You confirm this (and see which version of WSL) by running cat /etc/issue in your bash script. Your WSL environment will have an independent set of environment variables (not just $OSTYPE). You can see this by comparing the output of Get-ChildItem -Path Env:\ in PowerShell to the output of env (after you launch bash from PowerShell).
I suspect that the python version discrepancy you're seeing is a result of the PATH variable in your WSL runtime not matching what you have set in your PowerShell environment. You can fix your version issue by setting an alias containing a path to the python executable you want to use by adding alias python=/c/path/to/python.exe to the start of your bash scripts.
Alternatively, you can use a tool like Cygwin or git-bash to run your scripts. I'm not sure if they will use the same path variables as Windows so you may need to set those manually too.

wsl executes only bash commands and not windows options

When I try to execute cmd commands such as wsl -l, wsl returns this message:
/bin/bash: -c: option requires an argument
However, using wsl as a bash command launcher works.
What do I have to do in order to use wsl windows options such as wsl -l, wsl --install, etc.?
Thanks in advance!
I assume that you've entered wsl command in the Linux terminal and when you did this the first time bash answered you that the command was not found , so you installed 'wsl' package. This is a completely different package. If you want to invoke Windows binaries from bash you should use .exe file extension. Try wsl.exe -l

How to execute a binary added to $PATH inside WSL2 from CMD?

Inside my WSL2 environment I have adb added to the Path env variable. I want to invoke it directly from Windows CMD like so: wsl adb, but I receive the following error:
zsh:1: command not found: adb
It's as if it doesn't source ~/.zprofile when it runs the command and thus doesn't have the adjusted PATH variable. Any ideas how to deal with this? ZSH is the default shell inside my WSL2 environment and running adb from inside it works just fine.
I figured it out, this seems to work: wsl zsh -ic "adb"

Use WSL(Windows Subsystem for Linux) bash command in CMD

I am favorite user of WSL.
Before Restoring my Windows 10 OS, I setup WSL in my Windows and I didn't change any configuration. But One Day, the bash command were executed in CMD immediately. So, If I opened CMD and run a command such as 'ls', then result was the same in bash thing.
However now, I restore my windows and above command excuting no longer occurs. I often use bash commands, so I want to execute bash command in CMD. What should I do?

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.

Resources