Skip to content

spawn method use <<< redirection unexpected  #2700

Closed
@zhangwinning

Description

@zhangwinning

What steps will reproduce the bug?

test.js

#!/usr/bin/env node
let spawn = require("child_process").spawn;
function showContent(content) {
  spawn(`cat <<< "${content}" | less -r`, {
    stdio: "inherit", // use the current shell for stdio
    shell: true,
  });
}
showContent("hello");

-rwxr-xr-x  test.js

the function is executable. so ./test.js is ok. while error is produce. error is the following

/bin/sh: 1: Syntax error: redirection unexpected

How often does it reproduce? Is there a required condition?

on my mac OS, it is ok, while in the linux, the error will trigger.

What is the expected behavior?

perform normal

What do you see instead?

Additional information

I dig into the <<< redirection,The default system shell in Ubuntu is dash, not bash. Dash does not have the <<< redirection operator. that could be the problem. while I don't know how to solve it.
stackoverflow

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions