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

deploy Error: spawn UNKNOWN #94

Closed
xbotao opened this issue Dec 31, 2016 · 16 comments
Closed

deploy Error: spawn UNKNOWN #94

xbotao opened this issue Dec 31, 2016 · 16 comments

Comments

@xbotao
Copy link

xbotao commented Dec 31, 2016

I follow #70 to do.
But there is an error when I click the 'Deploy' button.
Error is
"Error: spawn UNKNOWN"


I use windows and firefox brower.

@pirtleshell
Copy link
Collaborator

Does hexo deploy function as expected when run from the command line?

@xbotao
Copy link
Author

xbotao commented Jan 1, 2017

The command hexo deploy is OK when run from the comamnd line.

@xbotao
Copy link
Author

xbotao commented Jan 1, 2017

Error Info

INFO  Start processing
INFO  Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.
EEE { Error: spawn UNKNOWN
    at exports._errnoException (util.js:953:11)
    at ChildProcess.spawn (internal/child_process.js:302:11)
    at exports.spawn (child_process.js:372:9)
    at module.exports (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\hexo-admin\deploy.js:14:14)
    at E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\hexo-admin\api.js:265:7
    at E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\hexo-admin\api.js:91:7
    at call (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:239:7)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:183:5)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\body-parser\lib\read.js:129:5
    at invokeCallback (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\raw-body\index.js:262:16)
    at done (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\raw-body\index.js:251:7)
    at IncomingMessage.onEnd (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\raw-body\index.js:307:7)
    at emitNone (events.js:86:13)
    at IncomingMessage.emit (events.js:185:7) code: 'UNKNOWN', errno: 'UNKNOWN', syscall: 'spawn' }

@pirtleshell
Copy link
Collaborator

Deploy uses child_process to run your deploy command. It looks like the UNKNOWN errors occur either from permissions issues (this stackoverflow question) or from how Windows doesn't support shebangs to directly run files (babel/minify#108 (comment)).

What is the admin.deployCommand of your _config.yml? Try running the command directly in the terminal. Does it deploy correctly?

@xbotao
Copy link
Author

xbotao commented Jan 2, 2017

Running the command directly in the terminal is correctly.
qq 20170102104526

admin:
  deployCommand: './hexo-deploy.sh'

and I try it on the ubuntu, it's OK.
I think windows doesn't support it.

@pirtleshell
Copy link
Collaborator

pirtleshell commented Jan 2, 2017

I think it's a permissions or shebang problem like from the posts mentioned above. You'll just have to play around with it to get it to work with Windows.

What are the contents of hexo-deploy.sh?

Does deploying work when you start hexo with administrative privileges (sudo hexo server)?

If that doesn't work, try setting deployCommand to the following and see if either of them work:

  • hexo deploy
  • sh hexo-deploy.sh
  • node ./node_modules/hexo/bin/hexo deploy

@xbotao
Copy link
Author

xbotao commented Jan 3, 2017

The contents of hexo-deploy.sh

#!/usr/bin/env sh
hexo g && hexo d

$ sudo hexo s -d
bash: sudo: command not found

admin:
  deployCommand: 'hexo deploy'

error log

res { Error: spawn hexo deploy ENOENT
    at exports._errnoException (util.js:953:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:182:32)
    at onErrorNT (internal/child_process.js:348:16)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn hexo deploy',
  path: 'hexo deploy',
  spawnargs: [ '' ] } { stdout: '', stderr: '' }

admin:
  deployCommand: 'sh hexo-deploy.sh'

error log

res { Error: spawn sh hexo-deploy.sh ENOENT
    at exports._errnoException (util.js:953:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:182:32)
    at onErrorNT (internal/child_process.js:348:16)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn sh hexo-deploy.sh',
  path: 'sh hexo-deploy.sh',
  spawnargs: [ '' ] } { stdout: '', stderr: '' }

admin:
  deployCommand: 'node ./node_modules/hexo/bin/hexo deploy'

error log

res { Error: spawn node ./node_modules/hexo/bin/hexo deploy ENOENT
    at exports._errnoException (util.js:953:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:182:32)
    at onErrorNT (internal/child_process.js:348:16)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn node ./node_modules/hexo/bin/hexo deploy',
  path: 'node ./node_modules/hexo/bin/hexo deploy',
  spawnargs: [ '' ] } { stdout: '', stderr: '' }

@xbotao
Copy link
Author

xbotao commented Jan 3, 2017

I found a compromise method to deploy blog by click the deploy button.

create a hexo-deploy.bat file

hexo d

and set the deployCommand to deployCommand: 'hexo-deploy.bat'
But a cmd console will pop when click the deploy button.

@xbotao
Copy link
Author

xbotao commented Jan 3, 2017

Accoding to this issue(Using nodejs's spawn causes “unknown option — ” and “[Error: spawn ENOENT]” errors)
I change
//var proc = spawn(command, [message], {detached: true});
to
var proc = spawn((process.platform === "win32" ? "hexo.cmd" : "hexo"), ['d']);

It works! Thanks for your patiently reply.

@xbotao xbotao closed this as completed Jan 3, 2017
@xbotao
Copy link
Author

xbotao commented Jan 3, 2017

sorry,
just spawn((process.platform === "win32" ? "hexo.cmd" : "hexo"), ['d']); is not correctly.

need generate before hexo d

var proc = spawn((process.platform === "win32" ? "hexo.cmd" : "hexo"), ['d', '-g']);

@xbotao
Copy link
Author

xbotao commented Jan 3, 2017

what I alter.And I test it on win10 and ubuntu.
api.js
deploy.js#L13
deploy.js#L16

@xbotao
Copy link
Author

xbotao commented Jan 4, 2017

Could you test this code and pull it? @pirtleshell

@pirtleshell
Copy link
Collaborator

This is good to know, but the idea of deployCommand is that many things can be run on deployment, not just hexo d -g. I think limiting deployment to just this one command would be a regression. Did you try setting hexo.cmd d -g as your deployCommand in _config.yml?

The batch file also worked for you, so I think the current functionality is good. This is a great thread for someone who has problems with deploying on windows in the future though! Thanks for the thorough explanation!

@xbotao
Copy link
Author

xbotao commented Jan 4, 2017

Got it.I think you mean,the current functionality cloud run any command you want rather than hexo g.

@pirtleshell
Copy link
Collaborator

pirtleshell commented Jan 5, 2017

That's right 😄 And it works on windows given the right command.

@xbotao
Copy link
Author

xbotao commented Jan 5, 2017

Accoding to the exec function define

 if (process.platform === 'win32') {
file = 'cmd.exe';
args = ['/s', '/c', '"' + command + '"'];
// Make a shallow copy before patching so we don't clobber the user's
// options object.
options = util._extend({}, options);
options.windowsVerbatimArguments = true;
} else {
  file = '/bin/sh';
  args = ['-c', command];
}

I think this can do like this on windows:
create a .bat file, content is

hexo deploy

and the deploy.js code is

  var proc;
  if(process.platform === "win32"){
    proc =  exec('hexo-deploy.bat');
  }else{
    proc = spawn(command, [message], {detached: true});
  }

the result is:
qq 20170105094715


There is a disadvantage of exec command, the options' maxBuffer is limited to 200k.
But I think 200K is enough in this enviroment.

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

No branches or pull requests

2 participants