Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executing batch command (cmd or bat) in windows fails #5

Closed
raleksandar opened this issue Apr 2, 2017 · 10 comments · Fixed by #6
Closed

Executing batch command (cmd or bat) in windows fails #5

raleksandar opened this issue Apr 2, 2017 · 10 comments · Fixed by #6

Comments

@raleksandar
Copy link
Contributor

raleksandar commented Apr 2, 2017

I'm trying to use multiview with yarn and I want to have this in my "scripts" section of package.json:

"dev": "yarn build:dev && multiview [yarn watch] [yarn run:api] [yarn run:server]"

But after the build:dev scripts finishes (just runs webpack with dev config) multiview starts and displays <command> (done) and Exited with code 1 for each command without ever running them.

I have confirmed that this is not due to webpack or nodemon (which are used in my watch and run:* tasks) by having this in my "scripts" section:

"testmv1": "multiview [yarn lsla]",
"testmv2": "multiview [ls -la]",
"lsla": "ls -la"

Running yarn testmv1 shows same behavior as my config (i.e. the lsla script is not executed by multiview and it reports exit code 1) while running yarn testmv2 executes ls -la and displays its output correctly.

I have tested this on Windows 10 (x64, latest insider fast build) with Node v7.8.0 and Yarn v0.22.0 (which is current RC, tried first with latest stable v0.21.3 but it's the same behavior with both versions).

@arjunmehta
Copy link
Owner

arjunmehta commented Apr 2, 2017

@raleksandar thanks for this. Can you tell me which version of multiview you're using? Is it installed via npm?

I'm honestly not too familiar with yarn so might need a bit of help understanding the underlying mechanisms yarn employs when invoking npm installed cli programs and in that context how they invoke yarn scripts :)

Multiview should technically take the commands and spawn them but depending on how yarn is invoked globally vs locally it may fail.

In your yarn config can you try a few things:
Try: multiview [yarn]
Try: multiview [yarn 'lsla']

What happens if you call these directly from the command line?
./node_modules/.bin/multiview [yarn lsla]

I'll try testing on my local environment too (macOS).

@raleksandar
Copy link
Contributor Author

Hi @arjunmehta, thanks for quick reply :)

I forgot to mention version of multiview I'm using, sorry, it's v2.5.1. I have been running it from local node_modules dir (i.e. didn't have multiview installed globally). But I have tried:

multiview [yarn] (after installing multiview with yarn global add multiview)
multiview [yarn lsla]
./node_modules/.bin/multiview [yarn]
./node_modules/.bin/multiview [yarn lsla]

And they all fail to run command (they give exit code 1 instead).

I have also verified running multiview (both local and global) without having yarn involved and both of these work:

multiview [ls -la]
./node_module/.bin/multiview [ls -la]

@raleksandar
Copy link
Contributor Author

Closed this accidentally :)

@raleksandar
Copy link
Contributor Author

I have just tried using npm run testmv1 instead of yarn, and I got exact same result (i.e. command not run, exit code 1 reported by multiview).

I've changed package.json to have following in scripts filed:

"testmv1": "multiview [npm run lsla]",
"testmv2": "multiview [ls -la]",
"lsla": "ls -la"

And running npm run testmv1 fails while npm run testmv2 works, same as with Yarn.

So.. not sure what exactly is the problem :)

@arjunmehta
Copy link
Owner

arjunmehta commented Apr 2, 2017

@raleksandar It seems to be working alright on macOS.
I've created a test project with package.json:

{
  "name": "yarnTest",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "lsla": "ls -la",
    "mv": "multiview [yarn lsla] [yarn lsla] -x 2000"
  },
  "dependencies": {
    "multiview": "^2.5.1"
  }
}

Running yarn mv executes correctly.

So, this may be windows specific, and may have something to do with how node executes npm "binaries" on windows.

Will look into it some more, but this will be difficult for me to test! :(

@raleksandar
Copy link
Contributor Author

I believe I've "fixed" it. Well, made it run multiview [yarn lsla] [yarn lsla] :)

I have added "shell" option in a call to child_process.spawn in lib/Spawn.js:

var spawnedProcess = spawn(command, args, {
    shell: 'cmd.exe'
 });

I'll test a bit more and if it's ok with you I could create a PR which would set shell option to cmd.exe if running on windows?

@arjunmehta
Copy link
Owner

Yes please contribute a fix! Can you also test with npm in addition to yarn?
This library is sadly very difficult to test for, but your solution makes a lot of sense.

I was going to point you to this: nodejs/node#3675

Definitely something to do with cmd.

@raleksandar
Copy link
Contributor Author

Tested with both yarn and npm, also ran couple of other Node.js binaries (webpack, gulp) via multiview. Everything works :)

@arjunmehta
Copy link
Owner

Nice! I reviewed your PR. Looks excellent, but I have a few code style nits before we merge.

@arjunmehta
Copy link
Owner

@raleksandar Thank you for your help!

@arjunmehta arjunmehta changed the title Running any yarn script in multiview doesn't work Executing batch command (cmd or bat) in windows fails Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants