0

So I have the following sequences of commands, and I don't believe it runs on Windows, but it runs on a Mac:

echo "istanbul cover /Users/Olegzandr/WebstormProjects/suman/test/build-tests/empty.test.js --dir ./coverage/empty.test
istanbul cover /Users/Olegzandr/WebstormProjects/suman/test/build-tests/tes-t7-start.test.js --dir ./coverage/tes-t7-start.test
istanbul cover /Users/Olegzandr/WebstormProjects/suman/test/build-tests/test6.test.js --dir ./coverage/test6.test
istanbul report --dir coverage --include **/*coverage.json lcov" | bash

So basically I have 4 individual statements (separated by a newline char) and I pipe those 4 commands through bash and it works on Mac (and probably on unix). But with Windows, it doesn't seem to work and I have no indication as to why. Bash is installed on my Windows machine, but since I am writing a library I need to assume bash is installed on all Windows machines - I assume this is true for Windows 7/8/10 etc.

Anyone have any idea why the above would work on Mac but not on Windows?

I tried the following:

    const cmd = "istanbul cover C:\Users\denman\WebstormProjects\suman\test\build-tests\empty.test.js --dir ./coverage/empty.test && istanbul cover C:\Users\denman\WebstormProjects\suman\test\build-tests\tes-t7-start.test.js --dir ./coverage/tes-t7-start.test && istanbul cover C:\U
    sers\denman\WebstormProjects\suman\test\build-tests\test6.test.js --dir ./coverage/test6.test && istanbul report --dir coverage --include **/*coverage.json lcov"

    cp.exec(cmd, function(err,stdout,stderr){

      ////
    });

and I got:

Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "istanbul cover C:\Users\denman\WebstormProjects\suman\test\build-tests\empty.test.js --dir ./coverage/empty.test&&istanbul cover C:\Users\denman\WebstormProjects\suman\test\build-tests\tes-t7-start.test.js -
-dir ./coverage/tes-t7-start.test&&istanbul cover C:\Users\denman\WebstormProjects\suman\test\build-tests\test6.test.js --dir ./coverage/test6.test&&istanbul report --dir coverage --include **/*coverage.json lcov"
=============================================================================
Writing coverage object [C:\Users\denman\WebstormProjects\suman\coverage\empty.test\coverage.json]
Writing coverage reports at [C:\Users\denman\WebstormProjects\suman\coverage\empty.test]
=============================================================================

    at ChildProcess.exithandler (child_process.js:203:12)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:818:16)
    at Socket.<anonymous> (internal/child_process.js:319:11)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at Pipe._onclose (net.js:469:12)

However, the first coverage report was generated for the first test file, but all subsequent commands failed.

Sir. Hedgehog
  • 1,260
  • 3
  • 17
  • 40
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • Does the string end up with DOS newlines? What do you get if you pipe to `bash -x`? – tripleee May 11 '16 at 07:20
  • It seems to work if I change && to &, I am not sure why, because none of the individual commands seem to fail out – Alexander Mills May 11 '16 at 07:27
  • also, as an aside, I would rather use cp.spawn instead of cp.exec using node.js, but seems difficult to figure out – Alexander Mills May 11 '16 at 07:28
  • 1
    FYI, bash is most certainly _not_ installed by default on Windows 7/8/10. There is [this](https://msdn.microsoft.com/en-us/commandline/wsl/about) but it's beta, not installed by default, and for Windows 10 only. – Thomas May 11 '16 at 07:30
  • yeah good call, I am just using cmd now with windows, and it works, if I figure out why will post an answer – Alexander Mills May 11 '16 at 07:39

1 Answers1

1

Bash on windows is only available on windows 10, not on others, as Thomas have replied.

Any tries to pipe into bash.exe from windows shell (both cmd/powershell) will fail with an error message Error: 0x80070057.

I've wrote a program to solve this by managing temporary pipe/argument files. http://github.com/chidea/GttBoW

Ch.Idea
  • 578
  • 6
  • 8