All Topics
All Topics
Technology
Technology
AI
AI
Business
Business
Entertainment
Entertainment
News
News
Programming
Programming
Security
Security
Science
Science
Design
Design
Environment
Environment
Finance
Finance
Crypto
Crypto
Politics
Politics
Sports
Sports
Education
Education
Gaming
Gaming
Art
Art
Music
Music
Health
Health
Books
Books
Food
Food
Travel
Travel
Personal
Personal
Bluesky
Twitter

Containers - exec() is now available for Containers

16d ago

Source

CloudflareContainers - exec() is now available for Containerscloudflare.com
Snippet from the RSS feed
exec() is now available for Containers . Use this.ctx.container.exec() to start processes inside a running Container, stream standard input and output, inspect exit codes, and signal each process. Call exec() from a class extending Container , or from another Durable Object through this.ctx.container . The associated Container must already be running. This example starts the Container when needed, then reads its Node.js version: JavaScript import { Container } from "@cloudflare/containers" ; export class MyContainer extends Container { async readVersion () { if ( ! this . ctx . container . running ) { await this . start () ; } const process = await this . ctx . container . exec ([ "node" , "--version" ]) ; const output = await process . output () ; const decoder = new TextDecoder () ; return { exitCode : output . exitCode , stdout : decoder . decode ( output . stdout ) , stderr : decoder . decode ( output . stderr ) , }; } } TypeScript import { Container } from "@cloudflare/containers" ; export class MyContainer extends Container { async readVersion () { if ( ! this . ctx . container . running ) { await this . start () ; } const process = await this . ctx . container . exec ([ "node" , "--version" ]) ; const output = await process . output () ; const decoder = new TextDecoder () ; return { exitCode : output . exitCode , stdout : decoder . decode ( output . stdout ) , stderr : decoder . decode ( output . stderr ) , }; } } The command array starts an executable directly, without an implicit shell. Invoke a shell explicitly for pipes, redirects, or variable expansion. One RPC method can coordinate multiple exec() calls in one caller-to-Durable Object round trip. It can also pass byte-oriented ReadableStream input or return streamed output with flow control. For options and streaming examples, refer to Execute commands .

You might also wanna read

Comments

Sign in to join the conversation.

No comments yet. Be the first.