0

I'm trying to work with Python and automate some tasks in IBM Spectrum Protect (A.K.A. TSM) tool. Normally, I would open a CMD with Admin privileges, change directory to where I have a Batch file for "TSM Administrative CLI tool", select the batch file and run.

The batch file (Name: TSM_Server_CLI.bat) contains the following:

@@echo Off
set OptFile="C:\tsm\config\dsm.opt"
call "Config\userConfig.bat"

%systemdrive%
cd "%programfiles%\Tivoli\TSM\baclient"

dsmadmc -optfile=%OptFile% -id=username

The "C:\tsm\config\dsm.opt" contains the TSM server information (Name, IP address). The "Config\userConfig.bat" only contains my userID. "set User="username"

Then, I would have to enter my password, but this can be saved in the batch file (-password=''), and then I start running TSM commands into the TSM server.

Now, I wanted to use Python to automate some of those commands and save an output file.

I'm able to open or run the batch file(TSM_Server_CLI.bat), which open a new CMD window, But I haven't found a way to send commands to that new CMD window or terminal, which is where I have to enter the TSM Commands.

tsm.py

os.chdir(r"C:\\tsm")
os.startfile("TSM_Server_CLI.bat")

I have found that "subprocess" module can help on this but I haven't found the correct script for it, and I'm not sure if this is even possible.

The plan is to have a series of commands in my python script to be send or executed into the CMD/terminal opened with "os.startfile".

For example:

  • Open TSM_Server_CLI.bat, which open a CMD window.
  • Run query node > output.csv
  • Run query session >> output.csv
  • etcetera.

I hope that explains my idea. thanks

  • `os.startfile` does not return a handle to the process, so you'd have to find the new console window to interact with it. Generally, you'd solve this kinda of problem using `subprocess` and (reading and writing to stdout and stdin on the process)[https://stackoverflow.com/questions/50434204/running-interactive-program-from-within-python] – Anon Coward Feb 11 '22 at 01:00
  • @AnonCoward thank you! subprocess.Popen() and stdout/stdin were needed – underpepe Feb 17 '22 at 18:04

0 Answers0