咖啡脚本意外令牌非法,但不应该有任何非法
Coffeescript unexpected token ILLEGAL, but there shouldn't be anything illegal
这真的很令人生气。我在我的代码中找不到我正在做任何非法事情的地方,但由于某种原因,调用fork
会炸毁我的程序。这是代码。相关部分在 svgToPNG 中,我称之为fork
。
{fork} = require 'child_process'
{Coral} = require 'coral'
svgToPNG = (svg, reply, log) ->
log "converting SVG to a PNG"
# set up a child process to call convert svg: png:-
convert = fork '/usr/bin/env', ['convert', 'svg:', 'png:-']
log "Spawned child process running convert, pid " + convert.pid
# set up behavior when an error occurs
convert.stderr.on "data", ->
log "Error occurred while executing convert"
reply "error"
# set up behavior for when we successfully convert
convert.stdout.on "data", ->
log "Successful conversion! :)"
log "here's the data: " + data
reply data
# pipe the SVG into the stdin of the process (starting it)
convert.stdin.end svg
如果我把fork
线拿出来,用别的东西代替它,一切都是笨拙的dory,但如果我把它留在里面,我会得到:
> coffee src/coral_client.coffee
finished doing conversion to svg!
converting SVG to a PNG
Spawned child process running convert, pid 60823
/usr/bin/grep:1
(function (exports, require, module, __filename, __dirname) { ����
^
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
这毫无意义。我没有任何像这个问题那样奇怪的非法 unicode 字符,我不相信我有任何像这个问题这样的解析错误......我真的不知道发生了什么。
可能是CoffeeScript以某种方式破坏了代码吗?这似乎不太可能,但我不知道。
错误在于您使用fork
。 fork
用于生成节点进程,即 foo.js
文件。 请改用spawn
。
我通过运行代码的精简版本,读取图像文件然后将其传递给您的svgToPNG
来解决这个问题。错误消息开始:
/usr/bin/env:1
(function (exports, require, module, __filename, __dirname) { ELF
在此复制/粘贴中呈现为ELF
字符是我的二进制/usr/bin/env
文件的头字符。 所以node.js
fork
正在尝试编译/usr/bin/env
文件。 查看child_process
文档证实了这一点。 运行 ls
和 grep
等内容的示例使用 spawn
。
相关文章:
- 我想在AngularJS应用程序中创建一个输入数字框,用户不应该在该框上键入十进制数字.(一个整数输入框)
- Javascript代码添加了一些不应该存在的内容
- 有没有任何情况下,一个方法不应该是原型方法
- 当我认为它不应该重新渲染视图时,如何防止 Meteor 在 html 选择 dom 单击事件上重新渲染视图
- Node.js Promise - 代码不应该等到 .then 完成()
- 跳跃运动:旋转轴 – 如果手静止不动,它不应该在 0 左右
- 如果我不应该在组件WillUpdate中调用setState,如何更新状态(使用ReactJS)
- Javascript:尝试从多个没有匹配的数组中采样,在不应该的时候循环递增
- 这个正则表达式不应该工作吗?
- 为什么不应该't我在JavaScript中使用Alert
- 如何避免隐藏不应该隐藏的部分
- 在对javascript/NodeJS应用程序进行原型设计时,应该测试什么,不应该测试什么
- 如果我不应该用流星吗;不需要反应性
- jQuery点击监听器在'It’不应该
- JavaScript排序函数排序时不应该排序
- Javascript插件不应该影响所有的选择框
- Javascript闭包:这个数组不应该通过getArray进行编辑
- Bootstrap Popover不应该每次都被破坏
- jquery 选择器总是选择,即使它不应该
- 咖啡脚本意外令牌非法,但不应该有任何非法