Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This plugin runs a command and reads data from its stdout (or stderr).
- **command**: command line (string, required)
- **pipe**: stdout or stderr (string, default: stdout)

The **command** is exected using a shell. So it can include pipe (`|`), environment variables (`$VAR`), redirects, and so on.
The **command** is exected using a shell (`sh -c` on UNIX/Linux, `PowerShell.exe -Command` on Windows). Therefore, it can include pipe (`|`), environment variables (`$VAR`), redirects, and so on.

## Example

Expand Down
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ configurations {
version = "0.1.3"

dependencies {
compile "org.embulk:embulk-core:0.7.0"
provided "org.embulk:embulk-core:0.7.0"
compile "org.embulk:embulk-core:0.7.+"
provided "org.embulk:embulk-core:0.7.+"
testCompile 'org.embulk:embulk-core:0.7.+:tests'
testCompile "junit:junit:4.+"
}

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/embulk/input/CommandFileInputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.InputStream;
import java.io.IOException;
import java.io.FilterInputStream;
import com.google.common.annotations.VisibleForTesting;
import org.slf4j.Logger;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -88,7 +89,7 @@ public TransactionalFileInput open(TaskSource taskSource, int taskIndex)
PluginTask task = taskSource.loadTask(PluginTask.class);

List<String> cmdline = new ArrayList<String>();
cmdline.addAll(SHELL);
cmdline.addAll(buildShell());
cmdline.add(task.getCommand());

logger.info("Running command {}", cmdline);
Expand Down Expand Up @@ -131,6 +132,17 @@ public TransactionalFileInput open(TaskSource taskSource, int taskIndex)
}
}

@VisibleForTesting
static List<String> buildShell()
{
String osName = System.getProperty("os.name");
if(osName.indexOf("Windows") >= 0) {
return ImmutableList.of("PowerShell.exe", "-Command");
} else {
return ImmutableList.of("sh", "-c");
}
}

private static class ProcessWaitInputStream
extends FilterInputStream
{
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/org/embulk/input/TestCommandFileInputPlugin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
package org.embulk.input;

import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.embulk.EmbulkTestRuntime;
import static org.embulk.input.CommandFileInputPlugin.buildShell;

import java.util.List;

import static org.junit.Assert.assertEquals;

public class TestCommandFileInputPlugin
{
@Rule
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();

@Test
public void testShell() {
if (System.getProperty("os.name").indexOf("Windows") >= 0) {
assertEquals(ImmutableList.of("PowerShell.exe", "-Command"), buildShell());
}
else {
assertEquals(ImmutableList.of("sh", "-c"), buildShell());
}
}
}