Skip to content

Commit 4177114

Browse files
committed
feat: runCommand to support interactive write+read
1 parent 13ff6fc commit 4177114

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,33 @@ await webcontainer.mount({
111111

112112
##### `runCommand`
113113

114-
Run command inside webcontainer. Returns command output.
114+
Run command inside webcontainer.
115115

116116
```ts
117117
await webcontainer.runCommand("npm", ["install"]);
118+
```
119+
120+
Calling `await` on the result resolves into the command output:
118121

122+
```ts
119123
const files = await webcontainer.runCommand("ls", ["-l"]);
120124
```
121125

126+
To write into the output stream, use `write` method of the non-awaited output.
127+
128+
To verify output of continuous stream, use `waitForText()`:
129+
130+
```ts
131+
const { write, waitForText, isDone } = webcontainer.runCommand("npm", [
132+
"create",
133+
"vite",
134+
]);
135+
136+
await waitForText("What would you like to call your project?");
137+
await write("Example Project");
138+
await isDone;
139+
```
140+
122141
##### `readFile`
123142

124143
WebContainer's [`readFile`](https://webcontainers.io/guides/working-with-the-file-system#readfile) method.

0 commit comments

Comments
 (0)