Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing Windows PowerShell commands in a Jupyter Notebook

Would someone please suggest a way to execute Windows PowerShell commands (i.e., commands more similar to Unix commands than Command-Prompt commands) in a Jupyter notebook? Please note that I am a layperson.

So far, I have added "C:\ProgramData\Anaconda3\Scripts" to my path system variable, which allows me to run "jupyter-notebook" from either Command Prompt or Windows PowerShell. I guess a shell looks in all folders in my path system variable for an application to run named "juypter-notebook". I guessed that running Jupyter Notebook from Windows PowerShell would allow my Jupyter-Notebook Chrome application to understand PowerShell commands, but this doesn't seem to be the case.

like image 834
Tom Lever Avatar asked Nov 02 '25 04:11

Tom Lever


1 Answers

You can execute a PowerShell command from a Jupyter Notebook cell on a Windows machine with:

!Powershell.exe -Command "<PowerShell command>"

For example, if you wanted to print the first 10 lines of the file filename.txt, you could write:

!Powershell.exe -Command "type filename.txt -Head 10"

Source

like image 146
pfischer1687 Avatar answered Nov 03 '25 19:11

pfischer1687



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!