Avatar ·

Python Interaction with cmd.exe

📁 example, AI

Need to call Windows command line, send a command (e.g. ipconfig). Then save the result to Notepad.

Tried via pywinauto/subprocess. Couldn't get past displaying the cmd screen.

How can this be implemented, or in which direction should I look?

Avatar ·

In your example, when encountering a line like: "aa,bb,cc", it is counted as "aabbcc 1", but it should be: aa 1 bb 1 cc 1

So, my version in Perl:

#!/usr/bin/perluse strict;my %result;while (<>) {    $result{ lc $_ }++ for /(\\w+)/g;}printf ""%-32s %d"", $_, $result{$_} for sort keys %result;

You can of course compress it into one line, but it will be unreadable.

Log in to leave an answer

Blogs