You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varexpress=require('express');varapp=express();varexpressWs=require('express-ws')(app);varos=require('os');varpty=require('node-pty');constfs=require('fs');constserver=require('./config/env');constnodeEnv=server.env;constport=nodeEnv.port;varterminals={},logs={};console.log('os.platform()',os.platform())varshell=os.platform()==='win32' ? 'C:\\Windows\\System32\\cmd.exe' : 'bash';//'cmd.exe' don't work eitherapp.use(function(req,res,next){res.header("Access-Control-Allow-Origin","*");// res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");next();});app.get('/',function(req,res){// res.sendFile(__dirname + '/index.html');console.log('get /')fs.readFile(__dirname+'/index.html',"utf8",(err,file)=>{if(err){next()}else{res.status(200).send(file);}});});app.post('/terminals',function(req,res){console.log('req.query.cols',req.query.cols)console.log('req.query.rows',req.query.rows)varcols=parseInt(req.query.cols),rows=parseInt(req.query.rows),term=pty.spawn(shell,[],{name: 'xterm-color',cols: cols||80,rows: rows||24,cwd: process.env.PWD,env: process.env});console.log('Created terminal with PID: '+term.pid);terminals[term.pid]=term;logs[term.pid]='';term.on('data',function(data){logs[term.pid]+=data;});res.send(term.pid.toString());res.end();});app.post('/terminals/:pid/size',function(req,res){varpid=parseInt(req.params.pid),cols=parseInt(req.query.cols),rows=parseInt(req.query.rows),term=terminals[pid];term.resize(cols,rows);console.log('Resized terminal '+pid+' to '+cols+' cols and '+rows+' rows.');res.end();});app.ws('/terminals/:pid',function(ws,req){varterm=terminals[parseInt(req.params.pid)];console.log('Connected to terminal '+term.pid);ws.send(logs[term.pid]);console.log('term',term)console.log('logs',logs)term.on('data',function(data){console.log('on data',data)try{ws.send(data);}catch(ex){// The WebSocket is not open, ignore}});ws.on('message',function(msg){console.log('on message',msg)term.write(msg);});ws.on('close',function(){term.kill();console.log('Closed terminal '+term.pid);// Clean things updeleteterminals[term.pid];deletelogs[term.pid];});});// var port = process.env.PORT || 6666,varhost=os.platform()==='win32' ? '127.0.0.1' : '0.0.0.0';console.log('App listening to http://'+host+':'+port);// app.listen(port, host);app.listen(port,host,err=>{console.log(err||'监听端口:'+port);// port is 6600});
my web-termimal
import*asTerminalfrom'../build/xterm';import*asattachfrom'../build/addons/attach/attach';import*asfitfrom'../build/addons/fit/fit';import*asfullscreenfrom'../build/addons/fullscreen/fullscreen';import*assearchfrom'../build/addons/search/search';import*aswebLinksfrom'../build/addons/webLinks/webLinks';import*aswinptyCompatfrom'../build/addons/winptyCompat/winptyCompat';Terminal.applyAddon(attach);Terminal.applyAddon(fit);Terminal.applyAddon(fullscreen);Terminal.applyAddon(search);Terminal.applyAddon(webLinks);Terminal.applyAddon(winptyCompat);varterm,protocol,socketURL,socket,pid;varterminalContainer=document.getElementById('terminal-container'),actionElements={findNext: document.querySelector('#find-next'),findPrevious: document.querySelector('#find-previous')},paddingElement=document.getElementById('padding');constserverUrl='http://127.0.0.1:6600'functionsetPadding(){term.element.style.padding=parseInt(paddingElement.value,10).toString()+'px';term.fit();}paddingElement.addEventListener('change',setPadding);actionElements.findNext.addEventListener('keypress',function(e){if(e.key==="Enter"){e.preventDefault();term.findNext(actionElements.findNext.value);}});actionElements.findPrevious.addEventListener('keypress',function(e){if(e.key==="Enter"){e.preventDefault();term.findPrevious(actionElements.findPrevious.value);}});createTerminal();functioncreateTerminal(){// Clean terminalwhile(terminalContainer.children.length){terminalContainer.removeChild(terminalContainer.children[0]);}term=newTerminal({});window.term=term;// Expose `term` to window for debugging purposesterm.on('resize',function(size){if(!pid){return;}varcols=size.cols,rows=size.rows,url=serverUrl+'/terminals/'+pid+'/size?cols='+cols+'&rows='+rows;fetch(url,{method: 'POST'});});protocol=(location.protocol==='https:') ? 'wss://' : 'ws://';socketURL=protocol+location.hostname+((location.port) ? (':'+location.port) : '')+'/terminals/';term.open(terminalContainer);term.winptyCompatInit();term.webLinksInit();term.fit();term.focus();// fit is called within a setTimeout, cols and rows need this.setTimeout(function(){initOptions(term);document.getElementById(`opt-cols`).value=term.cols;document.getElementById(`opt-rows`).value=term.rows;paddingElement.value=0;// Set terminal size again to set the specific dimensions on the demoupdateTerminalSize();fetch(serverUrl+'/terminals?cols='+term.cols+'&rows='+term.rows,{method: 'POST'}).then(function(res){res.text().then(function(processId){pid=processId;socketURL+=processId;socket=newWebSocket(socketURL);socket.onopen=runRealTerminal;socket.onclose=runFakeTerminal;socket.onerror=runFakeTerminal;});});},0);}functionrunRealTerminal(){term.attach(socket);term._initialized=true;}functionrunFakeTerminal(){if(term._initialized){return;}term._initialized=true;varshellprompt='$ ';term.prompt=function(){term.write('\r\n'+shellprompt);};term.writeln('Welcome to xterm.js');term.writeln('This is a local terminal emulation, without a real terminal in the back-end.');term.writeln('Type some keys and commands to play around.');term.writeln('');term.prompt();term.on('key',function(key,ev){varprintable=(!ev.altKey&&!ev.altGraphKey&&!ev.ctrlKey&&!ev.metaKey);if(ev.keyCode==13){term.prompt();}elseif(ev.keyCode==8){// Do not delete the promptif(term.x>2){term.write('\b \b');}}elseif(printable){term.write(key);}});term.on('paste',function(data,ev){term.write(data);});}functioninitOptions(term){varblacklistedOptions=[// Internal only options'cancelEvents','convertEol','debug','handler','screenKeys','termName','useFlowControl',// Complex option'theme',// Only in constructor'rendererType'];varstringOptions={bellSound: null,bellStyle: ['none','sound'],cursorStyle: ['block','underline','bar'],experimentalCharAtlas: ['none','static','dynamic'],fontFamily: null,fontWeight: ['normal','bold','100','200','300','400','500','600','700','800','900'],fontWeightBold: ['normal','bold','100','200','300','400','500','600','700','800','900']};varoptions=Object.keys(term.options);varbooleanOptions=[];varnumberOptions=[];options.filter(o=>blacklistedOptions.indexOf(o)===-1).forEach(o=>{switch(typeofterm.getOption(o)){case'boolean':
booleanOptions.push(o);break;case'number':
numberOptions.push(o);break;default:
if(Object.keys(stringOptions).indexOf(o)===-1){console.warn(`Unrecognized option: "${o}"`);}}});varhtml='';html+='<div class="option-group">';booleanOptions.forEach(o=>{html+=`<div class="option"><label><input id="opt-${o}" type="checkbox" ${term.getOption(o) ? 'checked' : ''}/> ${o}</label></div>`;});html+='</div><div class="option-group">';numberOptions.forEach(o=>{html+=`<div class="option"><label>${o} <input id="opt-${o}" type="number" value="${term.getOption(o)}"/></label></div>`;});html+='</div><div class="option-group">';Object.keys(stringOptions).forEach(o=>{if(stringOptions[o]){html+=`<div class="option"><label>${o} <select id="opt-${o}">${stringOptions[o].map(v=>`<option ${term.getOption(o)===v ? 'selected' : ''}>${v}</option>`).join('')}</select></label></div>`;}else{html+=`<div class="option"><label>${o} <input id="opt-${o}" type="text" value="${term.getOption(o)}"/></label></div>`}});html+='</div>';varcontainer=document.getElementById('options-container');container.innerHTML=html;// Attach listenersbooleanOptions.forEach(o=>{varinput=document.getElementById(`opt-${o}`);input.addEventListener('change',()=>{console.log('change',o,input.checked);term.setOption(o,input.checked);});});numberOptions.forEach(o=>{varinput=document.getElementById(`opt-${o}`);input.addEventListener('change',()=>{console.log('change',o,input.value);if(o==='cols'||o==='rows'){updateTerminalSize();}else{term.setOption(o,parseInt(input.value,10));}});});Object.keys(stringOptions).forEach(o=>{varinput=document.getElementById(`opt-${o}`);input.addEventListener('change',()=>{console.log('change',o,input.value);term.setOption(o,input.value);});});}functionupdateTerminalSize(){varcols=parseInt(document.getElementById(`opt-cols`).value,10);varrows=parseInt(document.getElementById(`opt-rows`).value,10);varwidth=(cols*term.renderer.dimensions.actualCellWidth+term.viewport.scrollBarWidth).toString()+'px';varheight=(rows*term.renderer.dimensions.actualCellHeight).toString()+'px';terminalContainer.style.width=width;terminalContainer.style.height=height;term.fit();}
error in app.js
os.platform()win32Applisteningto http://127.0.0.1:6600监听端口:6600req.query.cols87req.query.rows26
Error: Unabletostartterminal process: CreateProcessfailedatnewWindowsPtyAgent(E:\project\NodePtyCage\NodePty\node_modules\node-pty\lib\windowsPtyAgent.js:25:24)atnewWindowsTerminal(E:\project\NodePtyCage\NodePty\node_modules\node-pty\lib\windowsTerminal.js:45:24)atObject.spawn(E:\project\NodePtyCage\NodePty\node_modules\node-pty\lib\index.js:27:12)
at E:\project\NodePtyCage\NodePty\app.js:59:18atLayer.handle[ashandle_request](E:\project\NodePtyCage\NodePty\node_modules\express\lib\router\layer.js:95:5)atnext(E:\project\NodePtyCage\NodePty\node_modules\express\lib\router\route.js:137:13)atRoute.dispatch(E:\project\NodePtyCage\NodePty\node_modules\express\lib\router\route.js:112:3)atLayer.handle[ashandle_request](E:\project\NodePtyCage\NodePty\node_modules\express\lib\router\layer.js:95:5)
at E:\project\NodePtyCage\NodePty\node_modules\express\lib\router\index.js:281:22atFunction.process_params(E:\project\NodePtyCage\NodePty\node_modules\express\lib\router\index.js:335:12)
The text was updated successfully, but these errors were encountered:
Environment details
Issue description
why absolute path don't work for me 197
my app.js
my web-termimal
error in app.js
The text was updated successfully, but these errors were encountered: