2013-10-03 2 views
7

정말 격렬합니다. 어디에서나 불법적 인 일을하는 곳에서는 코드를 찾을 수 없지만 어떤 이유로 든 을 호출하면 프로그램이 망가질 수 있습니다. 여기에 코드가 있습니다. 관련 부분은 svgToPNG에 있으며 여기서 나는 fork이라고 부릅니다. 내가 밖으로 fork 라인을하고, 그 위치에 다른 내용을 교체 할 경우Coffeescript 예기치 않은 토큰 ILLEGAL, 불법적이면 안됩니다.

{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 

은, 모든 도리 늠름한,하지만 난 그것을에서 떠나면, 내가 얻을 :

> 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 

그것은 아무 의미가 없습니다. 난 this question 같은 이상한 불법 유니 코드 문자가 없어, 내가 어떤 종류의 구문 분석 오류가 있다고 생각하지 않아 this one ... 정말 무슨 일이 일어나고 있는지 모르겠다.

CoffeeScript가 어떻게 든 코드를 위반할 수 있습니까? 그럴 것 같지 않지만 모르겠다.

+0

어떤 파일을 변환하고 있습니까? 그것은'svg : somefilename png : -'로 변환하면 안됩니까? – hpaulj

+0

이 스크립트를 컴파일 한 다음'node'를 사용하여'js'를 실행하려고 시도 했습니까? 'js'가 잘 보이는 경우 문제는 coffeescript가 아닙니다. – hpaulj

+0

@hpaulj svg 파일이 프로세스의 표준 입력으로 파이프됩니다. –

답변

2

오류는 fork을 사용하고 있습니다. fork은 노드 프로세스를 생성하기위한 것으로, 즉 foo.js 개의 파일입니다. 대신 spawn을 사용하십시오.

코드를 제거하고 이미지 파일을 읽은 다음 svgToPNG에 전달하여이 문제를 해결했습니다. 오류 메시지가 시작 : ELF로이 복사/붙여 넣기 렌더링

/usr/bin/env:1 
(function (exports, require, module, __filename, __dirname) { ELF 

문자 내 진 /usr/bin/env 파일의 머리 문자입니다. 따라서 node.jsfork/usr/bin/env 파일을 컴파일하려고합니다. child_process 설명서를 검토하면이를 확인할 수 있습니다. lsgrep과 같은 항목을 실행하는 예는 spawn입니다.

+0

우수! 고마워! –

관련 문제