Python Forum
Windows/Power Shell: Differences from the tutorial... - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: Windows/Power Shell: Differences from the tutorial... (/thread-368.html)

Pages: 1 2 3


Windows/Power Shell: Differences from the tutorial... - diemildefreude - Oct-07-2016

I've switched to using the "Learn Python the Hard Way" method, which includes an appendix on learning to use the Powershell/other commandinput methods.

There are a few incongruities between the tutorial code and my results.

https://learnpythonthehardway.org/book/appendix-a-cli/ex8.html

E.g., the tutorial tells me to input

Quote:mkdir -p i/like/icecream

to make a chain of non-preexisting folders, each inside the previous. This isn't a legitimate syntax when I input it in PowerShell, whereas


Quote:mkdir i/like/icecream


works just fine. Also, the tutorial says you can't delete folders that contain other folders using "rmdir", but I can; I'm simply prompted to confirm.

These incongruities are not a big deal. Just wondering if there's something I need to be aware of. Also, I hope it's alright that this doesn't directly relate to Python.


RE: Windows/Power Shell: Differences from the tutorial... - wavic - Oct-07-2016

I am not sure if this is PowerShell or just cmd.


RE: Windows/Power Shell: Differences from the tutorial... - sparkz_alot - Oct-07-2016

(Oct-07-2016, 02:54 PM)wavic Wrote: I am not sure if this is PowerShell or just cmd.

Actually it's both, kind of. mkdir (or md) when used in powershell calls on PS's 'New-Item' cmdlet. The -p switch only exists in the unix/linux world, not DOS/Windows. So when PS parses the command, it ignores the '-p'. In cmd.exe the function mkdir does not ignore it, it fact it assumes it is another argument, "mkdir -p i/like/icecream" will actually create a directory "-p" as well as the directory tree "i/like/icecream". As you can imagine, there are heated debates on both sides on whether or not to use DOS commands or strictly cmdlets in powershell.

So my answer to the question, in the short term, use the mkdir or md in powershell, you're not going to break anything. In the big picture though, using DOS commands may end up in naming conflicts with PS, causing unexpected results. If you are planning on using powershell, then I would suggest learning powershell.


RE: Windows/Power Shell: Differences from the tutorial... - diemildefreude - Oct-08-2016

(Oct-07-2016, 08:26 PM)sparkz_alot Wrote:
(Oct-07-2016, 02:54 PM)wavic Wrote: I am not sure if this is PowerShell or just cmd.

Actually it's both, kind of. mkdir (or md) when used in powershell calls on PS's 'New-Item' cmdlet. The -p switch only exists in the unix/linux world, not DOS/Windows. So when PS parses the command, it ignores the '-p'. In cmd.exe the function mkdir does not ignore it, it fact it assumes it is another argument, "mkdir -p i/like/icecream" will actually create a directory "-p" as well as the directory tree "i/like/icecream". As you can imagine, there are heated debates on both sides on whether or not to use DOS commands or strictly cmdlets in powershell.

So my answer to the question, in the short term, use the mkdir or md in powershell, you're not going to break anything. In the big picture though, using DOS commands may end up in naming conflicts with PS, causing unexpected results. If you are planning on using powershell, then I would suggest learning powershell.

I tried entering in PowerShell, not cmd. It doesn't ignore just the '-p', but rather the whole command returns an error message. I've just tried in in cmd.exe and both "mkdir x/y/z" and "mkdir -p x/y/z" return syntax errors.

Also, deleting non-empty directories does indeed not work in cmd.exe, whereas PW asks you for confirmation.

So am I correct to understand that the maker of the tutorial made a mistake in including the -p in the windows part of the tutorial and saying you can't delete non-empty files? Or maybe I have a different version of Powershell...

I'll keep going with the tutorial for now. There haven't been any other incongruities aside from those two.


RE: Windows/Power Shell: Differences from the tutorial... - wavic - Oct-08-2016

Why don't you run mkdir --help or mkdir -h and see which is the proper command


RE: Windows/Power Shell: Differences from the tutorial... - snippsat - Oct-08-2016

Use cmder it's a lot better.


RE: Windows/Power Shell: Differences from the tutorial... - wavic - Oct-08-2016

I am a linux user. In general when I have some fluctuations about a command I open its man page or run it with help options


RE: Windows/Power Shell: Differences from the tutorial... - snippsat - Oct-08-2016

(Oct-08-2016, 12:13 PM)wavic Wrote: Why don't you run mkdir --help or mkdir -h and see which is the proper command
On Windows it is mkdir /?


RE: Windows/Power Shell: Differences from the tutorial... - wavic - Oct-08-2016

(Oct-08-2016, 01:04 PM)snippsat Wrote:
(Oct-08-2016, 12:13 PM)wavic Wrote: Why don't you run mkdir --help or mkdir -h and see which is the proper command
On Windows it is mkdir /?

I was curious too. But it seems both md and mkdir are available.


RE: Windows/Power Shell: Differences from the tutorial... - snippsat - Oct-08-2016

(Oct-08-2016, 01:12 PM)wavic Wrote: I was curious too. But it seems both md and mkdir are available.
Just aliases of the same command,here output from help.
Output:
C:\ λ mkdir /? Creates a directory. MKDIR [drive:]path MD [drive:]path If Command Extensions are enabled MKDIR changes as follows: MKDIR creates any intermediate directories in the path, if needed. For example, assume \a does not exist then:    mkdir \a\b\c\d is the same as:    mkdir \a    chdir \a    mkdir b    chdir b    mkdir c    chdir c    mkdir d which is what you would have to type if extensions were disabled.