All,
First, thanks for reading! I'm very new to python, and I'm trying to do something that seemingly feels impossible.
I'm using Python 3.x to write a script. This script, so far, only runs Windows "net use" command and gets back drive mapping info. The problem is that I need to be able to separate the information, but it's reading it as one list item.
Here's the code:
import subprocess
import os
import sys
import re
dc = []
workstations = []
if sys.platform != "win32":
print ("=== This script only runs on Windows OS systems ===")
sys.exit(1)
scanMsg = '''
Enumerating domain for controllers.....Please wait.....
'''
servers = subprocess.Popen(["net","use"], stdout=subprocess.PIPE, universal_newlines=True).communicate()[0]
dc.append(servers)
print (len(dc))
I'm just checking the length to see if the output I'm getting is split, but there's no way that I can see to split this output.
Here's what I should get:
New connections will be remembered.
Status Local Remote Network
-------------------------------------------------------------------------------
Disconnected Z: \\xxxx\c$ Microsoft Windows Network
The command completed successfully.
But here's what I get... (All I did to get the following is print(dc) instead of len(dc):
['New connections will be remembered.\n\n\nStatus Local Remote Network\n\n-----------------------
--------------------------------------------------------\nDisconnected Z: \\\\xxxx\\c$ Microsoft Window
s Network\nThe command completed successfully.\n\n']
Any ideas? I'm seeing that net use is dumping all of its output into the list, but I can't split it by anything since it only has 1 element (or at least I don't think I can).
So, my end goal is to run "net use", parse the drive information from that, and then perform more actions based off of drive information. I'll need to get the UNC path and drive letter out. Is that possible?
Please let me know if you need more info!
Thanks!