尝试创建一个Atom模块,但得到Uncaught TypeError:Bad Argument ChildProcess.spawn

时间:2014-11-15 00:32:41

标签: coffeescript atom-editor

我正在尝试创建一个简单的Atom模块来调用shell命令" pdflatex"将活动文件作为参数。这是我的.coffee文件,名为latex-compile.coffee

LatexCompileView = require './latex-compile-view'

module.exports =
  activate: ->
    atom.workspaceView.command "latex-compile:pdflatex", => @pdflatex()

  pdflatex: ->
    #This assumes the active file
    spawn = require('child_process').spawn()
    editor=atom.workspace.getActiveTextEditor()
    path = editor.getPath()
    fname = editor.getTitle()
    pdfl = spawn 'pdflatex',['-shell-escape','-halt-on-error','-output-directory',path,path+"/"+fname]
    pdfl.stdout.on 'data',(data) -> console.log data.toString().trim()
    pdfl.stderr.on 'data',(data) -> console.log data.toString().trim()

现在,当我在可以使用该命令的文件上运行该命令时,出现以下错误:

Uncaught TypeError: Bad argument 
ChildProcess.spawn                                     child_process.js:1134
exports.spawn                                          child_process.js:993
module.exports.pdflatex                              latex-compile.coffee:10
(anonymous function)                                 latex-compile.coffee:6 
handler              /Applications/Atom.app/Contents/Resources/app/src/space-pen-extensions.js:113
jQuery.event.dispatch /Applications/Atom.app/Contents/Resources/app/node_modules/space-pen/vendor/jquery.js:4681
elemData.handle /Applications/Atom.app/Contents/Resources/app/node_modules/space-pen/vendor/jquery.js:4359
module.exports.CommandRegistry.handleCommandEvent /Applications/Atom.app/Contents/Resources/app/src/command-registry.js:243
(anonymous function)                      /Applications/Atom.app/Contents/Resources/app/src/command-registry.js:3
module.exports.CommandPaletteView.confirmed     /Applications/Atom.app/Contents/Resources/app/node_modules/command-palette/lib/command-palette-view…:120
module.exports.SelectListView.confirmSelection  /Applications/Atom.app/Contents/Resources/app/src/select-list-view.js:331
(anonymous function) /Applications/Atom.app/Contents/Resources/app/src/select-list-view.js:113
handler /Applications/Atom.app/Contents/Resources/app/src/space-pen-extensions.js:113
jQuery.event.dispatch /Applications/Atom.app/Contents/Resources/app/node_modules/space-pen/vendor/jquery.js:4681
elemData.handle /Applications/Atom.app/Contents/Resources/app/node_modules/space-pen/vendor/jquery.js:4359
module.exports.CommandRegistry.handleCommandEvent /Applications/Atom.app/Contents/Resources/app/src/command-registry.js:243
(anonymous function) /Applications/Atom.app/Contents/Resources/app/src/command-registry.js:3
module.exports.KeymapManager.dispatchCommandEvent /Applications/Atom.app/Contents/Resources/app/node_modules/atom-keymap/lib/keymap-manager.js:544
module.exports.KeymapManager.handleKeyboardEvent /Applications/Atom.app/Contents/Resources/app/node_modules/atom-keymap/lib/keymap-manager.js:386
module.exports.WindowEventHandler.onKeydown

有什么想法吗?我对咖啡脚本和原子很新。

1 个答案:

答案 0 :(得分:0)

editor.getPath()返回正在编辑的文件的完整路径,包括文件名。没有必要将其与editor.getTitle()结合使用。