Executing a command with spaces using a tSystem component

 

Overview

This article explains how to execute a command that contains spaces using a tSystem component and also offers troubleshooting suggestions for potential problems you may encounter.

Environment

This procedure was written with:

  • Talend Open Studio for DI 5.0-r72978 and Talend Open Studio for DI 5.1-r79249
  • JDK version: Sun JDK build 1.6.0_26-b03
  • Operating system: Windows XP SP3

Procedure

This example shows how to execute a system command using a tSystem component to copy a file named "a b c.txt" (for example) from C:\  to D:\ in different Talend Studio releases.

Talend Studio v5.0-r72978 or previous versions

  1. Create a new job, then drag and drop a tSystem component from the Palette to the Job editor. 
  2. Enter the following Java code in the Command field:

    new String[]{"cmd","/c","copy","C:\\a b c.txt","D:\\"}

Talend Studio v5.1-r79249 or higher versions

Since Talend Studio 5.1, a new feature Use Array Command is provided. This feature allows you to set an array of commands. Below is an example introduces this feature:

  1. Create a new job, then drag and drop a tSystem component from Palette to the Job editor.
  2. Select the Use Array Command box, then add the commands as seen below in Command table.

Common Error: "Cannot find the specified file"

You will encounter the below error when executing a command with spaces as follows:

"cmd /c copy C:\\a b c.txt D:\\"

The system cannot find the specified file

This is because tSystem component truncates the command at the first space in the file name. To fix this problem, use the suggested workaround or upgrade to version 5.1 or higher.

Version History
Revision #:
1 of 1
Last update:
‎04-17-2017 07:36 PM
Updated by:
 
Labels (1)
Contributors