Python Forum
Windows/Power Shell: Differences from the tutorial...
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Windows/Power Shell: Differences from the tutorial...
#1
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/a...i/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.
Reply
#2
I am not sure if this is PowerShell or just cmd.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
(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.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#4
(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.
Reply
#5
Why don't you run mkdir --help or mkdir -h and see which is the proper command
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
Use cmder it's a lot better.
Reply
#7
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#8
(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 /?
Reply
#9
(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.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#10
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Huge black friday power supply sale at EVGA Larz60+ 0 2,093 Nov-21-2018, 08:06 PM
Last Post: Larz60+
  differences between py2 and py3 Skaperen 4 4,387 Feb-10-2018, 09:16 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020