forked from peter-can-write/cpp-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall-shell-process.html
More file actions
20 lines (20 loc) · 5.59 KB
/
call-shell-process.html
File metadata and controls
20 lines (20 loc) · 5.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta name="exporter-version" content="Evernote Mac 6.3 (452849)"/><meta name="altitude" content="449.1174011230469"/><meta name="author" content="petergoldsborough@hotmail.com"/><meta name="created" content="2015-07-16 09:52:15 +0000"/><meta name="latitude" content="46.61396277652175"/><meta name="longitude" content="14.26328767972114"/><meta name="source" content="desktop.mac"/><meta name="updated" content="2015-07-16 09:52:40 +0000"/><title>Call shell process</title></head><body>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #e83100">#include</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #43d34b"><cstdio></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #e83100"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><br/></span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #e448ab">int</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">main(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #e448ab">int</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">argc,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #e448ab">char</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">* argv [])<br/>
{<br/>
</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #02a1f3">FILE</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">* process;</span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;"> </span></span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;"> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #e448ab">if</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(! (process =</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">popen</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #43d34b">"rm adsf"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #43d34b">"r"</span>)))</span></span></div>
<div><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"> {<br/>
</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #e448ab">throw</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #02a1f3">std</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">::</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">runtime_error</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #43d34b">"Error opening shell process!"</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">);<br/>
}<br/>
<br/>
</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #e448ab">char</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">buffer [</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #f32300">1024</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">];<br/>
<br/>
</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #e448ab">while</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">fgets</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(buffer,</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #e448ab">sizeof</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">(buffer), process))<br/>
{<br/>
</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #02a1f3">std</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">::</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #703daa">cout</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures"><< buffer <<</span> <span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #02a1f3">std</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">::</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #3d1d81">endl</span><span style="font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures">;<br/>
}</span></div>
<div><span style="font-size: 11px;"><span style="font-family: Menlo;">}</span></span></div>
</body></html>