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 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:\\"}

    1_021.png


Talend Studio v5.1-r79249 or higher versions

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

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

    2_019.png


Common Error: "Cannot find the specified file"

When executing a command with spaces such as this one:

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

You will encounter the following error:

The system cannot find the specified file.

This is because the 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 #:
3 of 3
Last update:
‎06-19-2017 11:32 AM
Updated by:
 
Labels (1)
Tags (1)