[英]SyntaxError: Unexpected token ILLEGAL in Node Javascript
I am trying to execute a command using node JavaScript. 我正在尝试使用节点JavaScript执行命令。
var spawn = require('child_process').spawn,
cmd = spawn('java -cp C:\Java\jdk1.7.0_45\lib\dom4j.jar;C:\Java\jdk1.7.0_45\lib\geronimo-stax-api_1.0_spec-1.0.1.jar;C:\Java\jdk1.7.0_45\lib\gson-2.2.4.jar;C:\Java\jdk1.7.0_45\lib\mysql-connector-java-5.1.6.jar;C:\Java\jdk1.7.0_45\lib\ooxml-schemas-1.0.jar;C:\Java\jdk1.7.0_45\lib\poi-3.9-20121203.jar;C:\Java\jdk1.7.0_45\lib\poi-ooxml-3.9.jar;C:\Java\jdk1.7.0_45\lib\xmlbeans-2.5.0.jar;C:\Java\jdk1.7.0_45\lib\xmlbeans-xmlpublic-2.6.0.jar;C:\Java\jdk1.7.0_45\lib\excelreader.jar astral.excelreader.Main 11 33 fsdds', []);
Then it is showing the following error: 然后显示以下错误:
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
If I remove these two jars (C:\\Java\\jdk1.7.0_45\\lib\\xmlbeans-2.5.0.jar;C:\\Java\\jdk1.7.0_45\\lib\\xmlbeans-xmlpublic-2.6.0.jar;)
from command then it is not showing the above error. 如果我删除这两个jar
(C:\\Java\\jdk1.7.0_45\\lib\\xmlbeans-2.5.0.jar;C:\\Java\\jdk1.7.0_45\\lib\\xmlbeans-xmlpublic-2.6.0.jar;)
从命令,则它不会显示上述错误。 But I want some class files in that jars. 但是我想要在罐子里放一些类文件。
If I run the first command directly in windows command prompt(without using node js) then it will execute correcty. 如果我直接在Windows命令提示符下运行第一个命令(不使用节点js),则它将正确执行。 Anybody know why that error comes if I add these following jars?
有人知道如果我添加以下这些jar,为什么会出现该错误?
C:\\Java\\jdk1.7.0_45\\lib\\xmlbeans-2.5.0.jar; C:\\Java\\jdk1.7.0_45\\lib\\xmlbeans-xmlpublic-2.6.0.jar;
String c:\\windows\\
in javascript should be like this: javascript中的字符串
c:\\windows\\
应该是这样的:
c:\\windows\\
And spawn syntax: spawn(command, [args], [options])
以及spawn语法:
spawn(command, [args], [options])
spawn('java', ['-cp', 'c:\\java\\...'])
You have to double the backslashes. 您必须将反斜杠加倍。 Instead of
代替
'java -cp C:\Java\jdk1.7.0_45\lib\dom4j.jar;...'
write 写
'java -cp C:\\Java\\jdk1.7.0_45\\lib\\dom4j.jar;...'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.