-
Notifications
You must be signed in to change notification settings - Fork 923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HELP]How to feed stdin into os.exec? #163
Comments
You can create a pipe and pass one of its end as the stdin parameter of exec (I think there are some examples in the tests directory. You can also take a look at a small lib I worked on which provide some utilities such as async exec + easier input management, as well as more complete curl support (https://github.com/ctn-malone/qjs-ext-lib/blob/master/doc/process.md) |
Something like this should work
|
Thank you very much for this I really appreciate. It works on short base64 encoded strings however when I try on a big file (see attached, it's a base64 encoded .ts video file from a m3u8 stream) it hangs. i tried strace to see what was going on but all I could see was : Do you have any idea why? Thank you. |
Might be related to the fact that you're expecting to decode binary data and not text. You should read from the pipe using ArrayBuffer and not utf8 string. Of you can just do |
It comes from a csv file with base64 encoded data that needs to be put back together to get the full base64 data te be decoded into a .ts video file. Attached is a file called sample_code.txt (rename to .js) which does all of that and spits out the full base64 data to be decoded which is where I am stuck. The data.csv file is the source for sample_code.js. It should be run as qjs -m sample_code.js > base64Encoded. EDIT 1:when I then do EDIT 2: You mentioned 'You should read from the pipe using ArrayBuffer' this makes sense indeed since the data is binary as you noticed but how would I do that? Sorry for my poor if not non-existent programming skills. As I said doing |
Try like this (ie: you can open a file and use it to redirect the output of the exec process) |
Thank you so much it worked!!! |
Hi,
first of all thank you for this it's really a big help for me. I have the following code which allows me to use the linux base64 utility to decode a base64 encoded file:
`'use strict';
import * as std from 'std';
import * as os from 'os';
var result = os.exec(["/bin/sh", "-c", "base64 -d file"]);
console.log(result);`
It works really well and is fast (I had a base64 decode js function but it was to slow that's why I use exec), however I was wondering how to feed a variable containing the base64 data directly to the base64 utility? It says that it takes a file as input and when no file is specified takes data from stdin (on a terminal feeding data through a pipe 'echo "string" | base64 -d -' will work), how could I achieve this and write the result to a file with quickjs please? I looked for a solution online but just couldn't find anything that made sense to me.
Thank you for your help.
The text was updated successfully, but these errors were encountered: