xterm - terminal output - javascript - Help needed in decoding this output - javascript

I am using the xterm.js library to integrate terminal in my react code. my websocket is connected to a windows device but after executing certain commands and getting the output, i am not getting the correct output but a gibberish string which i cannot understand.
Can somehelp help me in decoding this to string, ...
[?25l[93ma[?25h[m[?25l[93maa[?25h[m[?25l[93m[7;25Haaa[?25h[m[?25l[93m[7;25Haaaa[?25h[m[?25l[93m[7;25Haaaaa[?25h[m[?25l[93m[7;25Haaaaaa[?25h[m[?25l[93m[7;25Haaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[?25h[?25l[m[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[?25h[m[?25l[93m[7;25Haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[?25h[?25l[m[93m[7;

Related

Why do I get a bash: syntax error near unexpected token on every bit of code with VS Code?

I am very new to coding, and have just installed VS Code, and installed Node.js as well as Git Bash. I was working on a project, but couldn't console.log anything as I always received the following error when using Git Bash:
bash: syntax error near unexpected token `validateCred' (One of the
variables I used)
I created a new JS file, and ran the following code:
const hello = 'hello world';
I still received the same bash error. I have tried replacing my code with code that I know works and still receive the same errors.I have also tried using Powershell as my terminal, but receive the following errors every time:
batch : The term 'batch' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and
try again.
I am at a loss, and I'm sure it's something really simple, but I can't seem to figure it out!
A Bash shell expects you to enter Bash code and not JavaScript code.
If you want to run JavaScript code then you need to run it in Node.js and not in Bash.
Generally, the command node will launch Node.js in a Bash shell. (Assuming it is installed on the $PATH).

LocalStack - CloudFormation Returns Error Code: 500

I'm currently want to simulate AWS environment using LocalStack. But upon creating-stacks, the service returned me a error code: 500.
Here's my template file:
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Sample'
Resources:
sample:
Type: AWS::Lambda::Function
Properties:
MemorySize: 256
Timeout: 10
Runtime: nodejs8.10
Handler: /dist/service/src/handler.sample
Code:
Zipfile: lambda.zip
Here's the command i'm trying to run:
aws cloudformation create-stack \
--template-body file://localstack/cloudtemplate.yaml \
--stack-name sample \
--endpoint-url=http://localhost:4581 \
And here's the output:
Unable to parse response (syntax error: line 1, column 54), invalid XML received:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>
It seems that the cloudformation endpoint of the localstack doesn't work properly. Am i missing something?
The error you get back from LocalStack is quite vague so you need to dig in a bit deeper. First of all can you post how you start LocalStack (is it through Docker and if so what is the exact command line)?
Using Docker and docker-compose:
version: '3'
services:
localstack:
image: localstack/localstack:latest
ports:
- "4567-4584:4567-4584"
- "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
environment:
- SERVICES=cloudformation
- HOSTNAME=localstack
- DEFAULT_REGION=eu-west-2
- PORT_WEB_UI=${PORT_WEB_UI- }
- DEBUG=1
A few things to note here:
DEBUG=1 will give you the exact error in the console you execute the docker-compose from which may (or may not) help you diagnose the actual issue
You need to make sure that Cloudformation is started (by adding it in the SERVICES array) and that the appropriate port is opened. The default is 4581 (I am just using the default setup above opening all the ports LocalStack uses)
:latest is used. I had an older version of the image and had issues with Cloudformation which went away by upgrading to latest. Not sure at which point this was fixed but I guess it does not matter.
And to ensure that the issue is not with your template try using one that works, e.g. pick one from here:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html
Using the SQS Queue with Cloudwatch Alarms YAML example the following command works for me:
aws cloudformation create-stack --stack-name myteststack --template-body file://cloudf.yml --endpoint-url=http://localhost:4581
If the above works and you still have issues with your template then at least you know where the issue lies (and maybe you can post the more detailed DEBUG output).

where to find console in Node-RED

I can't find the console for Node-RED.
Do I have to use Node-RED Runtime API's RED.log()? Some Node-RED frontends, like FRED, seem to have a console. Also here a console is mentioned.
Is there a console accessible on the shell, or do I have to use the debug-Node?
Thanks in advance
Peter
Node-RED outputs data to the terminal it is started on.
So if you start it manually on the command line with node-red or node red it will print to the terminal.
If you've installed Node-RED as a service so it is launched at startup then it will depend on what platform you are on as to where the console log will end up. On Linux then there is a fair chance that it will end up in the journal and can be tailed with the following command:
sudo journalctl -f -u nodered -o cat
If you're running Node-RED on Bluemix then the you can see the console with the cf command line too:
cf logs <app-name>
or you can see it in the Bluemix web console.
As for sending data to this output then you have a few of options.
The Debug node has an option to output to the console, this is useful when the msg object (or msg.payload) is too big to fit in the debug side bar.
When writing your own nodes then you can use RED.log, This will add a time stamp and a node id to the output which can be useful when debugging.
At a pinch you can use console.log, but this will just dump things to standard out with no formatting or time stamp

Capturing console output in node.js with out editing server code

First stackoverflow question! I am trying to capture all console.log() output from a node.js server. Assume I am on a linux machine and I cannot edit the server's code, (project leader's request). I can, however change how I start the server (node --debug server.js) and I can attach shell scripts. My intent is to pipe the console output into another socket.io server.
I am thinking the only obvious solutions are to either write a linux command to pipe output of the server into something or node.js has a tricky --debug method to output the information.
End result, I want to be able to run the server and pipe the console output to a API testing server. That way, a tester would be able to see, streaming, the output of the server in correlation to the response JSON objects from the API end points.
Thanks, I would love to hear your solutions...
Answered over IRC, if anyone's interested:
<shesek> patrickm, can't you just pipe the output to another script?
<shesek> node server.js | node send-logs-to-somewhere.js
<shesek> patrickm, in send-logs-to-somewhere.js, you can just read from process.stdin
<patrickm> :)
<patrickm> thats easy

Writing a pseudo terminal in python for a web based ubuntu terminal

I am interested in writing a web based terminal which can execute and autocomplete the commands in ubuntu terminal.
I have fiddled with Anyterm http://www.anyterm.org which uses ROTE: "a simple C library for VT102 terminal emulation" at the backend server and javascript/html for the terminal ui. The problem was that I couldn't have it open two terminals in the same window.
After doing some research I've decided to write a terminal server/pseudo terminal (whichever is the right terminology) in python which can:
execute commands in ubuntu terminal (such as ls, grep etc...)
autocomplete the commands (like $gedi (pressed tab) $gedit)
and have multiple instances of terminal open at the same time (when typed ls in one, the other terminal won't recognize ls as the last command since its another terminal session)
I have found that with pty python module I can write a pseudo terminal
however I'm new to python and I couldn't even get the example on that page to work.
I'm planning to have the python script serve a http server with the javascript/html terminal ui I would write (this was the main reason I wanted to choose python for this project). Then I want to let the web ui talk to the backend terminal "server" and get the results back to the web ui.
If you could point me in the right direction, maybe tell me which module I should use -if not pty- and give me some ideas on how to write the python pseudo terminal server I would appreciate it.
I know javascript/php and familiar with bash scripting- At this point I could go for a C based or python based backend server, is python right for this project?
Note: I'm planning to write a ui that uses ajax post or get methods to retrieve the terminal output from backend server.
You need to learn the basic terminology first. The shell is the program that interprets your input command lines, such as grep "foo" abc.txt. A terminal emulator is a program that mimics a terminal. Terminal is a device with display and keyboard that one
used in 1970s to access a UNIX mainframe. A pseudoterminal, pty is the device node supporting terminal emulators, as opposed to "real terminal devices" (tty1) for example.
Now, you could either build a shell, that would work in terminal instead of bash or dash; or you could build a terminal emulator that is usable over the internet; you could run any existing shell in it. Both are challenging tasks by themselves.
Python documentation is not of much use, I recommend you should start by googling more of these concepts first - and not only python references, but C, C++ too.
And lastly, if you want to run Emacs or nano or some other advanced program in your shell, you want to use the pty module.
I had a friends who did something similar but he did it over Google chat, I don't know how much help it will be but take a look at xmpp (python modual) maybe it could help you, or even here is a link to his source code:
chatIO
I didn't work with him on it but it was really easy for him to use
Good Luck

Categories