Would Python make a good substitute for the Windows command-line/batch scripts?

后端 未结 12 869
醉酒成梦
醉酒成梦 2021-01-30 07:21

I\'ve got some experience with Bash, which I don\'t mind, but now that I\'m doing a lot of Windows development I\'m needing to do basic stuff/write basic scripts using the Wind

相关标签:
12条回答
  • 2021-01-30 07:55

    I've done a decent amount of scripting in both Linux/Unix and Windows environments, in Python, Perl, batch files, Bash, etc. My advice is that if it's possible, install Cygwin and use Bash (it sounds from your description like installing a scripting language or env isn't a problem?). You'll be more comfortable with that since the transition is minimal.

    If that's not an option, then here's my take. Batch files are very kludgy and limited, but make a lot of sense for simple tasks like 'copy some files' or 'restart this service'. Python will be cleaner, easier to maintain, and much more powerful. However, the downside is that either you end up calling external applications from Python with subprocess, popen or similar. Otherwise, you end up writing a bunch more code to do things that are comparatively simple in batch files, like copying a folder full of files. A lot of this depends on what your scripts are doing. Text/string processing is going to be much cleaner in Python, for example.

    Lastly, it's probably not an attractive alternative, but you might also consider VBScript as an alternative. I don't enjoy working with it as a language personally, but if portability is any kind of concern then it wins out by virtue of being available out of the box in any copy of Windows. Because of this I've found myself writing scripts that were unwieldy as batch files in VBScript instead, since I can't usually depend on Python or Perl or Bash being available on Windows.

    0 讨论(0)
  • 2021-01-30 07:56

    Anything is a good replacement for the Batch file system in windows. Perl, Python, Powershell are all good choices.

    0 讨论(0)
  • 2021-01-30 07:58

    Python is well suited for these tasks, and I would guess much easier to develop in and debug than Windows batch files.

    The question is, I think, how easy and painless it is to ensure that all the computers that you have to run these scripts on, have Python installed.

    0 讨论(0)
  • 2021-01-30 08:05

    Are you aware of PowerShell?

    0 讨论(0)
  • 2021-01-30 08:08

    I've been using a lot of Windows Script Files lately. More powerful than batch scripts, and since it uses Windows scripting, there's nothing to install.

    0 讨论(0)
  • 2021-01-30 08:10

    Python, along with Pywin32, would be fine for Windows automation. However, VBScript or JScript used with the Winows Scripting Host works just as well, and requires nothing additional to install.

    0 讨论(0)
提交回复
热议问题