or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

executable-finder.mdindex.mdlegacy-process.mdmodern-process.md

legacy-process.mddocs/

0

# Legacy Process Management

1

2

Deprecated command-line execution utilities maintained for backward compatibility. These classes are marked as deprecated and should not be used in new implementations. Use the modern `ExternalProcess` API instead.

3

4

## Capabilities

5

6

### CommandLine Class

7

8

Deprecated wrapper for command-line execution with environment variable management and library path configuration.

9

10

```java { .api }

11

/**

12

* @deprecated Use ExternalProcess.Builder instead for new implementations

13

*/

14

@Deprecated

15

public class CommandLine {

16

/**

17

* Create command line with executable and arguments

18

* @param executable the executable to run

19

* @param args command arguments

20

*/

21

public CommandLine(String executable, String... args);

22

23

/**

24

* Set multiple environment variables

25

* @param environment map of environment variables

26

* @throws IllegalArgumentException if any value is null

27

*/

28

public void setEnvironmentVariables(Map<String, String> environment);

29

30

/**

31

* Set single environment variable

32

* @param name variable name (must not be null)

33

* @param value variable value (must not be null)

34

* @throws IllegalArgumentException if name or value is null

35

*/

36

public void setEnvironmentVariable(String name, String value);

37

38

/**

39

* Set dynamic library path for the platform

40

* @param newLibraryPath new library path (null values ignored)

41

*/

42

public void setDynamicLibraryPath(String newLibraryPath);

43

44

/**

45

* Append to existing dynamic library path

46

* @param extraPath path to append (null values ignored)

47

*/

48

public void updateDynamicLibraryPath(String extraPath);

49

50

/**

51

* Get platform-specific library path environment variable name

52

* @return "PATH" on Windows, "DYLD_LIBRARY_PATH" on Mac, "LD_LIBRARY_PATH" on Linux

53

*/

54

public static String getLibraryPathPropertyName();

55

56

/**

57

* Execute command asynchronously

58

*/

59

public void executeAsync();

60

61

/**

62

* Execute command and wait for completion

63

*/

64

public void execute();

65

66

/**

67

* Wait for process to start

68

* @param duration time to wait

69

* @param unit time unit

70

* @return true if process started within timeout

71

*/

72

public boolean waitForProcessStarted(long duration, TimeUnit unit);

73

74

/**

75

* Wait for process completion indefinitely

76

*/

77

public void waitFor();

78

79

/**

80

* Wait for process completion with timeout

81

* @param timeout timeout in milliseconds

82

*/

83

public void waitFor(long timeout);

84

85

/**

86

* Check if exit code is 0

87

* @return true if process completed successfully

88

*/

89

public boolean isSuccessful();

90

91

/**

92

* Get process exit code

93

* @return exit code of completed process

94

* @throws IllegalStateException if process still running

95

*/

96

public int getExitCode();

97

98

/**

99

* Get stdout output as string

100

* @return process output

101

*/

102

public String getStdOut();

103

104

/**

105

* Destroy the process

106

* @return exit code after destruction

107

*/

108

public int destroy();

109

110

/**

111

* Check if process is still running

112

* @return true if process is running

113

*/

114

public boolean isRunning();

115

116

/**

117

* Set input to send to process

118

* @param allInput input string

119

*/

120

public void setInput(String allInput);

121

122

/**

123

* Set working directory

124

* @param workingDirectory directory path

125

*/

126

public void setWorkingDirectory(String workingDirectory);

127

128

/**

129

* Copy output to additional stream

130

* @param out output stream

131

*/

132

public void copyOutputTo(OutputStream out);

133

134

/**

135

* Check for execution errors

136

*/

137

public void checkForError();

138

139

/**

140

* String representation of command and environment

141

* @return string representation

142

*/

143

public String toString();

144

}

145

```

146

147

**Usage Examples (Deprecated - Use ExternalProcess instead):**

148

149

```java

150

import org.openqa.selenium.os.CommandLine;

151

import java.util.HashMap;

152

import java.util.Map;

153

154

// Basic execution (deprecated pattern)

155

CommandLine cmd = new CommandLine("echo", "Hello", "World");

156

cmd.execute();

157

String output = cmd.getStdOut();

158

System.out.println("Output: " + output);

159

160

// Environment configuration (deprecated pattern)

161

CommandLine cmd = new CommandLine("java", "-jar", "myapp.jar");

162

cmd.setEnvironmentVariable("JAVA_OPTS", "-Xmx2g");

163

cmd.setDynamicLibraryPath("/opt/myapp/lib");

164

cmd.setWorkingDirectory("/opt/myapp");

165

166

// Asynchronous execution (deprecated pattern)

167

cmd.executeAsync();

168

boolean started = cmd.waitForProcessStarted(5, TimeUnit.SECONDS);

169

if (started) {

170

cmd.waitFor(30000); // Wait up to 30 seconds

171

if (cmd.isSuccessful()) {

172

System.out.println("Command completed successfully");

173

} else {

174

System.err.println("Command failed with exit code: " + cmd.getExitCode());

175

}

176

}

177

```

178

179

### OsProcess Class

180

181

Internal deprecated process management implementation used by CommandLine. This class is package-private and not intended for direct use.

182

183

```java { .api }

184

/**

185

* @deprecated Internal implementation class - do not use directly

186

*/

187

@Deprecated

188

class OsProcess {

189

/**

190

* Create OS process with executable and arguments

191

* @param executable executable to run

192

* @param args command arguments

193

*/

194

public OsProcess(String executable, String... args);

195

196

/**

197

* Set environment variable

198

* @param name variable name (must not be null)

199

* @param value variable value (must not be null)

200

* @throws IllegalArgumentException if name or value is null

201

*/

202

public void setEnvironmentVariable(String name, String value);

203

204

/**

205

* Get unmodifiable environment variables map

206

* @return environment variables

207

*/

208

public Map<String, String> getEnvironment();

209

210

/**

211

* Execute process asynchronously

212

*/

213

public void executeAsync();

214

215

/**

216

* Wait for process to start

217

* @param duration time to wait

218

* @param unit time unit

219

* @return true if started within timeout

220

*/

221

public boolean waitForProcessStarted(long duration, TimeUnit unit);

222

223

/**

224

* Wait for process completion

225

* @throws InterruptedException if interrupted

226

*/

227

public void waitFor() throws InterruptedException;

228

229

/**

230

* Wait for process completion with timeout

231

* @param timeout timeout in milliseconds

232

* @throws InterruptedException if interrupted

233

*/

234

public void waitFor(long timeout) throws InterruptedException;

235

236

/**

237

* Check if process is running

238

* @return true if running

239

*/

240

public boolean isRunning();

241

242

/**

243

* Get exit code

244

* @return process exit code

245

* @throws IllegalStateException if still running

246

*/

247

public int getExitCode();

248

249

/**

250

* Check for execution errors

251

*/

252

public void checkForError();

253

254

/**

255

* Get stdout as string

256

* @return process output

257

*/

258

public String getStdOut();

259

260

/**

261

* Set process input

262

* @param allInput input string

263

*/

264

public void setInput(String allInput);

265

266

/**

267

* Set working directory

268

* @param workingDirectory directory

269

*/

270

public void setWorkingDirectory(File workingDirectory);

271

272

/**

273

* Copy output to stream

274

* @param out output stream

275

*/

276

public void copyOutputTo(OutputStream out);

277

278

/**

279

* Destroy process

280

* @return exit code

281

*/

282

public int destroy();

283

284

/**

285

* String representation

286

* @return string representation

287

*/

288

public String toString();

289

}

290

```

291

292

### Migration to Modern API

293

294

For new implementations, migrate from the deprecated legacy API to the modern ExternalProcess API:

295

296

**Legacy Pattern (Deprecated):**

297

```java

298

// DON'T USE - Deprecated approach

299

CommandLine cmd = new CommandLine("git", "status");

300

cmd.setEnvironmentVariable("GIT_DIR", "/path/to/repo");

301

cmd.setWorkingDirectory("/path/to/repo");

302

cmd.execute();

303

String output = cmd.getStdOut();

304

```

305

306

**Modern Pattern (Recommended):**

307

```java

308

// USE THIS - Modern approach

309

ExternalProcess process = ExternalProcess.builder()

310

.command("git", Arrays.asList("status"))

311

.environment("GIT_DIR", "/path/to/repo")

312

.directory("/path/to/repo")

313

.start();

314

315

boolean completed = process.waitFor(Duration.ofSeconds(30));

316

if (completed) {

317

String output = process.getOutput();

318

int exitCode = process.exitValue();

319

} else {

320

process.shutdown();

321

}

322

```

323

324

### Key Differences

325

326

**Resource Management:**

327

- Legacy: Manual process cleanup required

328

- Modern: Automatic resource management with proper cleanup

329

330

**Error Handling:**

331

- Legacy: Mixed exception types (WebDriverException, TimeoutException)

332

- Modern: Consistent UncheckedIOException for startup failures

333

334

**Configuration:**

335

- Legacy: Setter methods after construction

336

- Modern: Builder pattern with fluent configuration

337

338

**Thread Safety:**

339

- Legacy: Limited thread safety guarantees

340

- Modern: Designed for single-threaded use per instance

341

342

**Output Handling:**

343

- Legacy: String-only output with manual buffer management

344

- Modern: Configurable buffering with charset support