That should allow you to manipulate your OS commands separately. Once you have the OS components operating as desired for your requirements, you can look at imbedding everything directly into the xp_cmdshell execution string again.
Use Notepad to create a new text file. Copy and paste (or retype) everything normally typed into a "DOSprompt command line window" into the text file. Rename the file something like 'c:\MyConnectBatchFile.cmd'.
Verify that the MyConnectBatchFile.cmd functions correctly (as you expect) by running it interactively (double clicking on it).
Note: A pause or other interactive dos command left in a .cmd file (for testing, etc.) will cause exec xp_cmdshell 'c:\MyConnectBatchFile.cmd' to appear to 'hang'. It will never get input to continue, and the process will then have to be killed (in taskmanager)!!
Once MyConnectBatchFile.cmd functions as expected interactively; call it from QA, using xp_cmdshell. For example:
exec xp_cmdshell 'c:\MyConnectBatchFile.cmd'