-1

I was trying to execute a batch file using SSIS execute process task. This task accepts only one argument. The argument is @[User::TabProjectName]=www.servername Dev_Admin Password123 DENMARK DEV V_Weekly_DEV.This is a space-separated string. How to split this single string into multiple substrings based on space and assigned to variables as shown below using Batch command?

set servername=www.servername
set username=Dev_Admin
set tabpwd=Password123
set sitename=DENMARK
set projectname=DEV
set datasourcename=V_Weekly_DEV
user1254579
  • 3,901
  • 21
  • 65
  • 104
  • 2
    Please [format your code and sample input/output properly](http://meta.stackexchange.com/a/22189/248777). – mklement0 Jan 10 '20 at 17:05
  • 1
    The argument contains spaces, so the usual course of action is to enclose the string in doublequotes. This would be received in a well written program as `%~1`, _which removes the enclosing doublequotes as a result of its expansion_, and passes as you had intended. The other thing you could consider is changing the program's `%1` argument to `%*` and seeing if your existing, _unquoted_, string works for you then. – Compo Jan 10 '20 at 17:57

1 Answers1

1

This was originally posted with a powershell tag, so this is how it can be done with powershell:

$string = '@[User::TabProjectName]=www.servername Dev_Admin Password123 DENMARK DEV V_Weekly_DEV'

$splitString = $string.split()

$serverName = $splitString[0].split('=')[1]
$username = $splitString[1]
$tabPwd = $splitString[2]
$siteName = $splitString[3]
$projectname = $splitString[4]
$datasourceName = $splitString[5]

$splitString, splits the initial string on spaces as no character is passed to the split operator. Each item in the split array can be referenced by its place number. The $serverName needs an additional split to get the data to the right of the '=' sign.

Shamus Berube
  • 466
  • 3
  • 12