Four Stars

Executing a command with multiple spaces and parameter using a tSystem component

Hi, I need to execute this command in tSystem:

cmd /c "my path to exe with spaces" "my first param with spaces" my second param with spaces"

and with context

context.CMD + context.EXE + context.firstParam + context.secondParam

 

I tried many different ways, als single commen, array command, with \" for inserting a double quote...

nothing works so far.

 

Does anyone know, how the correct syntax would be?

1 ACCEPTED SOLUTION

Accepted Solutions
Six Stars

Re: Executing a command with multiple spaces and parameter using a tSystem component

Hi Roland,

 

If you need to run on both Windows and Linux, it's very likely that the structure of the commands you'll be using will be (or could later become) very different, and you may find it much more straightforward and easier to maintain with two tSystem components, routing to the correct one using Run If with conditions based on another context variable.

 

I often use a dummy tJava component for this:

 

tSystem_PlatformSpecific.png

 

Continuing for now with the current approach, you don't need the first quote, plus you'll need to ensure there is always a space after the contents of EDXMain1, and the easiest way to do this, rather than having to remember each time you change the context variable, is to add this space before the two double quotes you're including between EDXMain1 and EDXMain2.

 

I tend to find when building strings for things like shell commands, it's useful to build them in e.g. a tMap, and then output the resultant string using a tLogRow, as I can copy this and try running it directly in the shell. Once I'm happy with everything, I then just copy the expression to wherever it's actually needed.

 

Regards,

 

 

Chris

6 REPLIES
Six Stars

Re: Executing a command with multiple spaces and parameter using a tSystem component

Hi there,

 

You need to add an extra set of double quotes around the entire thing after /c, but there's no need to escape the spaces, as follows:

 

cmd /c ""my path to exe with spaces" "my first param with spaces" "my second param with spaces""

       ^                                                          ^                            ^

 

I've indicated the ones which have been added.

 

Note they have been added at the start, and end, but in the example you posted there was also one missing at the start of the second parameter.

 

Regards,

 

 

Chris

Four Stars

Re: Executing a command with multiple spaces and parameter using a tSystem component

Hi,

thx for the help.

But I does not resolve the issue.

I did some more investigation on this.

If I use an array commend with these 4 parameters:

1. cmd

2. /c

3. c:\pathtoexecutable\my batch.bat

4. parameter one

 

3. contains a blank

4. contains a blank

This is working using pure java but not with Talen tSystem.

If I take out the blank in 3. , it works.

If I take out the blank it 4. , it works.

 

But if I have blanks in 3. and 4. (or more 5, 6, ...)

it is not working.

 

And,

if I use this as a parameter i.e. 

5. -taks=myTasks

it also causes an error, regardles if there are blanks in 3. and 4. or not.

 

Actually I redesigned my app.

I created a new batch file without any blanks in the name and path.

This batch I use in 3. and pass all neede values to it in 4. 5. 6. ....

But, I do not use this syntax: -task=myTask

I only pass myTask.

In the batch file I then created the needed string for calling the executable and pass

all parameters in the needed syntax.

 

 

 

KR

Roland

Six Stars

Re: Executing a command with multiple spaces and parameter using a tSystem component

Hi Roland,

 

I suspect this issue is either down to not fully quoting the individual parameters in the tSystem component, or possibly the way the parameter strings are being formed.

 

If the parameters are Context variables, then they to do not need to be escaped, but if you're building parameters yourself in code/expressions, then you'll need to escape the slashes (just double them up, so \ becomes \\) in any literal strings you are using, otherwise you could easily end up with carriage returns (\r) or newlines (\n) etc. in your strings.

 

A quick example using Context variables and just a single tSystem component, where the executable and parameters all have spaces:

 

Context2.png

 

tSystem.png

 

As expected, this will open up Notepad++ with the files specified by the two parameters.

 

Regards,

 

 

Chris

Four Stars

Re: Executing a command with multiple spaces and parameter using a tSystem component

Hi Chris,

thx, that works but does not fill 100% what I need.

Because the script needs to run on Windows and Linux machines,

I also need the cmd /c in a context parameter.

And if I try that, aligned to your syntax, 

I am still getting errors ;-(

I tried this:

"\""
+ context.EDXMain1
+ "\" \""
+ context.EDXMain2 
+ "\" \""
+ context.EDXParam1
+ "\"\""

 

Main 1 contains: cmd /c

Main 2 contains: pathtoexe\my script.bat

Param1 contains: my parameter

Six Stars

Re: Executing a command with multiple spaces and parameter using a tSystem component

Hi Roland,

 

If you need to run on both Windows and Linux, it's very likely that the structure of the commands you'll be using will be (or could later become) very different, and you may find it much more straightforward and easier to maintain with two tSystem components, routing to the correct one using Run If with conditions based on another context variable.

 

I often use a dummy tJava component for this:

 

tSystem_PlatformSpecific.png

 

Continuing for now with the current approach, you don't need the first quote, plus you'll need to ensure there is always a space after the contents of EDXMain1, and the easiest way to do this, rather than having to remember each time you change the context variable, is to add this space before the two double quotes you're including between EDXMain1 and EDXMain2.

 

I tend to find when building strings for things like shell commands, it's useful to build them in e.g. a tMap, and then output the resultant string using a tLogRow, as I can copy this and try running it directly in the shell. Once I'm happy with everything, I then just copy the expression to wherever it's actually needed.

 

Regards,

 

 

Chris

Four Stars

Re: Executing a command with multiple spaces and parameter using a tSystem component

thx!!