├── COPYING.FPC ├── COPYING.txt ├── README.md ├── demo-simple ├── Unit1.dfm ├── Unit1.pas ├── demo.dpr └── demo.dproj ├── demo2 ├── demo2.dpr └── demo2.dproj ├── demo3 ├── Unit1.dfm ├── Unit1.pas ├── demo3.dpr └── demo3.dproj ├── dpipes.pas ├── dprocess.pas ├── pipes_win.inc └── process_win.inc /COPYING.FPC: -------------------------------------------------------------------------------- 1 | This is the file COPYING.FPC, it applies to the Free Pascal Run-Time Library 2 | (RTL) and packages (packages) distributed by members of the Free Pascal 3 | Development Team. 4 | 5 | The source code of the Free Pascal Runtime Libraries and packages are 6 | distributed under the Library GNU General Public License 7 | (see the file COPYING) with the following modification: 8 | 9 | As a special exception, the copyright holders of this library give you 10 | permission to link this library with independent modules to produce an 11 | executable, regardless of the license terms of these independent modules, 12 | and to copy and distribute the resulting executable under terms of your choice, 13 | provided that you also meet, for each linked independent module, the terms 14 | and conditions of the license of that module. An independent module is a module 15 | which is not derived from or based on this library. If you modify this 16 | library, you may extend this exception to your version of the library, but you are 17 | not obligated to do so. If you do not wish to do so, delete this exception 18 | statement from your version. 19 | 20 | If you didn't receive a copy of the file COPYING, contact: 21 | Free Software Foundation 22 | 675 Mass Ave 23 | Cambridge, MA 02139 24 | USA 25 | 26 | -------------------------------------------------------------------------------- /COPYING.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | 504 | 505 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TProcess-Delphi 2 | TProcess for Delphi, ported from Freepascal 3 | 4 | ## About TProcess 5 | TProcess allows one to capture the output from an executable in a cross platform way without using low level API calls and pipes (this is a wrapper around them). 6 | 7 | Many developers have complained that there is no equivalent in Delphi which freepascal already has, so why not port it? That's what this project intends to do. 8 | 9 | Initial port done for MS Windows. 10 | More work done on this soon: get it working in Firemonkey, macOS port (so long as FireMonkey has the needed Macos/Unix functions in the RTL which fpc used) 11 | -------------------------------------------------------------------------------- /demo-simple/Unit1.dfm: -------------------------------------------------------------------------------- 1 | object Form2: TForm2 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form2' 5 | ClientHeight = 328 6 | ClientWidth = 552 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -13 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | PixelsPerInch = 120 15 | TextHeight = 16 16 | object Label1: TLabel 17 | Left = 176 18 | Top = 8 19 | Width = 305 20 | Height = 16 21 | Caption = 'This program captures the output of a command' 22 | end 23 | object Memo1: TMemo 24 | Left = 8 25 | Top = 39 26 | Width = 520 27 | Height = 276 28 | Lines.Strings = ( 29 | 'Output:' 30 | '') 31 | TabOrder = 0 32 | end 33 | object Button1: TButton 34 | Left = 24 35 | Top = 8 36 | Width = 121 37 | Height = 25 38 | Caption = 'Run Command' 39 | TabOrder = 1 40 | OnClick = Button1Click 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /demo-simple/Unit1.pas: -------------------------------------------------------------------------------- 1 | unit Unit1; 2 | 3 | interface 4 | 5 | uses 6 | Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 7 | Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; 8 | 9 | type 10 | TForm2 = class(TForm) 11 | Memo1: TMemo; 12 | Button1: TButton; 13 | Label1: TLabel; 14 | procedure Button1Click(Sender: TObject); 15 | private 16 | { Private declarations } 17 | public 18 | { Public declarations } 19 | end; 20 | 21 | var 22 | Form2: TForm2; 23 | 24 | implementation 25 | 26 | {$R *.dfm} 27 | 28 | uses 29 | dprocess; // TProcess from FPC, ported to delphi 30 | 31 | procedure TForm2.Button1Click(Sender: TObject); 32 | var output: ansistring; 33 | begin 34 | RunCommand('cmd', ['/c', 'dir'], output, [poNoConsole]); 35 | memo1.Lines.Add(output); 36 | end; 37 | 38 | end. 39 | -------------------------------------------------------------------------------- /demo-simple/demo.dpr: -------------------------------------------------------------------------------- 1 | program demo; 2 | 3 | uses 4 | Vcl.Forms, 5 | Unit1 in 'Unit1.pas' {Form2}; 6 | 7 | {$R *.res} 8 | 9 | begin 10 | Application.Initialize; 11 | Application.MainFormOnTaskbar := True; 12 | Application.CreateForm(TForm2, Form2); 13 | Application.Run; 14 | end. 15 | -------------------------------------------------------------------------------- /demo-simple/demo.dproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {62D1442F-4766-4600-9270-49E715227BCE} 4 | 18.2 5 | VCL 6 | demo.dpr 7 | True 8 | Debug 9 | Win32 10 | 1 11 | Application 12 | 13 | 14 | true 15 | 16 | 17 | true 18 | Base 19 | true 20 | 21 | 22 | true 23 | Base 24 | true 25 | 26 | 27 | true 28 | Base 29 | true 30 | 31 | 32 | true 33 | Cfg_1 34 | true 35 | true 36 | 37 | 38 | true 39 | Base 40 | true 41 | 42 | 43 | true 44 | Cfg_2 45 | true 46 | true 47 | 48 | 49 | .\$(Platform)\$(Config) 50 | .\$(Platform)\$(Config) 51 | false 52 | false 53 | false 54 | false 55 | false 56 | RESTComponents;FireDAC;FireDACSqliteDriver;soaprtl;FireDACIBDriver;soapmidas;FireDACCommon;RESTBackendComponents;soapserver;CloudService;FireDACCommonDriver;inet;$(DCC_UsePackage) 57 | System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) 58 | $(BDS)\bin\delphi_PROJECTICON.ico 59 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png 60 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png 61 | demo 62 | 63 | 64 | DBXSqliteDriver;IndyIPCommon;bindcompdbx;DBXInterBaseDriver;vcl;IndyIPServer;vclactnband;DSPack_Tokyo;vclFireDAC;IndySystem;tethering;svnui;dsnapcon;FireDACADSDriver;FireDACMSAccDriver;fmxFireDAC;vclimg;vcltouch;vcldb;bindcompfmx;svn;FireDACPgDriver;inetdb;DbxCommonDriver;fmx;fmxdae;xmlrtl;fmxobj;vclwinx;rtl;DbxClientDriver;DCEF_Tokyo1;CustomIPTransport;vcldsnap;dbexpress;IndyCore;vclx;bindcomp;appanalytics;dsnap;IndyIPClient;bindcompvcl;VCLRESTComponents;dbxcds;VclSmp;adortl;vclie;bindengine;DBXMySQLDriver;dsnapxml;FireDACMySQLDriver;dbrtl;IndyProtocols;inetdbxpress;FireDACCommonODBC;fmxase;$(DCC_UsePackage) 65 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) 66 | Debug 67 | true 68 | CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= 69 | 1033 70 | $(BDS)\bin\default_app.manifest 71 | 72 | 73 | DBXSqliteDriver;IndyIPCommon;bindcompdbx;DBXInterBaseDriver;vcl;IndyIPServer;vclactnband;vclFireDAC;IndySystem;tethering;dsnapcon;FireDACADSDriver;FireDACMSAccDriver;fmxFireDAC;vclimg;vcltouch;vcldb;bindcompfmx;FireDACPgDriver;inetdb;DbxCommonDriver;fmx;fmxdae;xmlrtl;fmxobj;vclwinx;rtl;DbxClientDriver;CustomIPTransport;vcldsnap;dbexpress;IndyCore;vclx;bindcomp;appanalytics;dsnap;IndyIPClient;bindcompvcl;VCLRESTComponents;dbxcds;VclSmp;adortl;vclie;bindengine;DBXMySQLDriver;dsnapxml;FireDACMySQLDriver;dbrtl;IndyProtocols;inetdbxpress;FireDACCommonODBC;fmxase;$(DCC_UsePackage) 74 | 75 | 76 | DEBUG;$(DCC_Define) 77 | true 78 | false 79 | true 80 | true 81 | true 82 | 83 | 84 | false 85 | true 86 | true 87 | ..\;$(DCC_UnitSearchPath) 88 | true 89 | 1033 90 | 91 | 92 | false 93 | RELEASE;$(DCC_Define) 94 | 0 95 | 0 96 | 97 | 98 | true 99 | true 100 | 101 | 102 | 103 | MainSource 104 | 105 | 106 |
Form2
107 | dfm 108 |
109 | 110 | Cfg_2 111 | Base 112 | 113 | 114 | Base 115 | 116 | 117 | Cfg_1 118 | Base 119 | 120 |
121 | 122 | Delphi.Personality.12 123 | Application 124 | 125 | 126 | 127 | Microsoft Office 2000 Sample Automation Server Wrapper Components 128 | Microsoft Office XP Sample Automation Server Wrapper Components 129 | 130 | 131 | demo.dpr 132 | 133 | 134 | 135 | 136 | 137 | demo.exe 138 | true 139 | 140 | 141 | 142 | 143 | 1 144 | 145 | 146 | Contents\MacOS 147 | 1 148 | 149 | 150 | Contents\MacOS 151 | 0 152 | 153 | 154 | 155 | 156 | classes 157 | 1 158 | 159 | 160 | 161 | 162 | library\lib\armeabi-v7a 163 | 1 164 | 165 | 166 | 167 | 168 | library\lib\armeabi 169 | 1 170 | 171 | 172 | 173 | 174 | library\lib\mips 175 | 1 176 | 177 | 178 | 179 | 180 | library\lib\armeabi-v7a 181 | 1 182 | 183 | 184 | 185 | 186 | res\drawable 187 | 1 188 | 189 | 190 | 191 | 192 | res\values 193 | 1 194 | 195 | 196 | 197 | 198 | res\drawable 199 | 1 200 | 201 | 202 | 203 | 204 | res\drawable-xxhdpi 205 | 1 206 | 207 | 208 | 209 | 210 | res\drawable-ldpi 211 | 1 212 | 213 | 214 | 215 | 216 | res\drawable-mdpi 217 | 1 218 | 219 | 220 | 221 | 222 | res\drawable-hdpi 223 | 1 224 | 225 | 226 | 227 | 228 | res\drawable-xhdpi 229 | 1 230 | 231 | 232 | 233 | 234 | res\drawable-small 235 | 1 236 | 237 | 238 | 239 | 240 | res\drawable-normal 241 | 1 242 | 243 | 244 | 245 | 246 | res\drawable-large 247 | 1 248 | 249 | 250 | 251 | 252 | res\drawable-xlarge 253 | 1 254 | 255 | 256 | 257 | 258 | 1 259 | 260 | 261 | Contents\MacOS 262 | 1 263 | 264 | 265 | 0 266 | 267 | 268 | 269 | 270 | Contents\MacOS 271 | 1 272 | .framework 273 | 274 | 275 | 0 276 | 277 | 278 | 279 | 280 | 1 281 | .dylib 282 | 283 | 284 | 1 285 | .dylib 286 | 287 | 288 | 1 289 | .dylib 290 | 291 | 292 | Contents\MacOS 293 | 1 294 | .dylib 295 | 296 | 297 | 0 298 | .dll;.bpl 299 | 300 | 301 | 302 | 303 | 1 304 | .dylib 305 | 306 | 307 | 1 308 | .dylib 309 | 310 | 311 | 1 312 | .dylib 313 | 314 | 315 | Contents\MacOS 316 | 1 317 | .dylib 318 | 319 | 320 | 0 321 | .bpl 322 | 323 | 324 | 325 | 326 | 0 327 | 328 | 329 | 0 330 | 331 | 332 | 0 333 | 334 | 335 | 0 336 | 337 | 338 | Contents\Resources\StartUp\ 339 | 0 340 | 341 | 342 | 0 343 | 344 | 345 | 346 | 347 | 1 348 | 349 | 350 | 1 351 | 352 | 353 | 1 354 | 355 | 356 | 357 | 358 | 1 359 | 360 | 361 | 1 362 | 363 | 364 | 1 365 | 366 | 367 | 368 | 369 | 1 370 | 371 | 372 | 1 373 | 374 | 375 | 1 376 | 377 | 378 | 379 | 380 | 1 381 | 382 | 383 | 1 384 | 385 | 386 | 1 387 | 388 | 389 | 390 | 391 | 1 392 | 393 | 394 | 1 395 | 396 | 397 | 1 398 | 399 | 400 | 401 | 402 | 1 403 | 404 | 405 | 1 406 | 407 | 408 | 1 409 | 410 | 411 | 412 | 413 | 1 414 | 415 | 416 | 1 417 | 418 | 419 | 1 420 | 421 | 422 | 423 | 424 | 1 425 | 426 | 427 | 428 | 429 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 430 | 1 431 | 432 | 433 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 434 | 1 435 | 436 | 437 | 438 | 439 | 1 440 | 441 | 442 | 1 443 | 444 | 445 | 446 | 447 | ..\ 448 | 1 449 | 450 | 451 | ..\ 452 | 1 453 | 454 | 455 | 456 | 457 | 1 458 | 459 | 460 | 1 461 | 462 | 463 | 1 464 | 465 | 466 | 467 | 468 | 1 469 | 470 | 471 | 1 472 | 473 | 474 | 1 475 | 476 | 477 | 478 | 479 | ..\ 480 | 1 481 | 482 | 483 | 484 | 485 | Contents 486 | 1 487 | 488 | 489 | 490 | 491 | Contents\Resources 492 | 1 493 | 494 | 495 | 496 | 497 | library\lib\armeabi-v7a 498 | 1 499 | 500 | 501 | 1 502 | 503 | 504 | 1 505 | 506 | 507 | 1 508 | 509 | 510 | 1 511 | 512 | 513 | Contents\MacOS 514 | 1 515 | 516 | 517 | 0 518 | 519 | 520 | 521 | 522 | 1 523 | 524 | 525 | 1 526 | 527 | 528 | 529 | 530 | Assets 531 | 1 532 | 533 | 534 | Assets 535 | 1 536 | 537 | 538 | 539 | 540 | Assets 541 | 1 542 | 543 | 544 | Assets 545 | 1 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | True 559 | False 560 | 561 | 562 | 12 563 | 564 | 565 | 566 | 567 |
568 | -------------------------------------------------------------------------------- /demo2/demo2.dpr: -------------------------------------------------------------------------------- 1 | { Console program demo showing use of TProcess 2 | 3 | License: This demo is BSD/MIT 4 | But dprocess.pas is FPC Modified LGPL (okay for commercial) 5 | } 6 | 7 | program demo2; 8 | 9 | {$APPTYPE CONSOLE} 10 | 11 | {$R *.res} 12 | 13 | uses sysutils, classes, dprocess; 14 | 15 | procedure DoLog(s: string); 16 | begin 17 | writeln(s); 18 | end; 19 | 20 | function RunProcess(const Binary: string; args: TStrings): boolean; 21 | const 22 | BufSize = 1024; 23 | var 24 | p: TProcess; 25 | // Buf: string; 26 | Buf: ansistring; 27 | Count: integer; 28 | i: integer; 29 | LineStart: integer; 30 | // OutputLine: string; 31 | OutputLine: ansistring; 32 | begin 33 | p := TProcess.Create(nil); 34 | try 35 | p.Executable := Binary; 36 | 37 | p.Options := [poUsePipes, 38 | poStdErrToOutPut]; 39 | // p.CurrentDirectory := ExtractFilePath(p.Executable); 40 | p.ShowWindow := swoShowNormal; // Is this needed? 41 | 42 | p.Parameters.Assign(args); 43 | DoLog('Running command '+ p.Executable +' with arguments: '+ p.Parameters.Text); 44 | p.Execute; 45 | 46 | { Now process the output } 47 | OutputLine:=''; 48 | SetLength(Buf,BufSize); 49 | repeat 50 | if (p.Output<>nil) then 51 | begin 52 | Count:=p.Output.Read(Buf[1],Length(Buf)); 53 | // Count:=p.Output.Read(pchar(Buf)^, BufSize); //L505 todo: try this when using unicodestring buffer 54 | // writeln('DEBUG: len buf: ', length(buf)); 55 | end 56 | else 57 | Count:=0; 58 | LineStart:=1; 59 | i:=1; 60 | while i<=Count do 61 | begin 62 | // L505 63 | //if Buf[i] in [#10,#13] then 64 | if CharInSet(Buf[i], [#10,#13]) then 65 | begin 66 | OutputLine:=OutputLine+Copy(Buf,LineStart,i-LineStart); 67 | writeln(OutputLine); 68 | OutputLine:=''; 69 | // L505 70 | //if (iBuf[i+1]) then 71 | if (iBuf[i+1]) then 72 | inc(i); 73 | LineStart:=i+1; 74 | end; 75 | inc(i); 76 | end; 77 | OutputLine:=Copy(Buf,LineStart,Count-LineStart+1); 78 | until Count=0; 79 | if OutputLine <> '' then 80 | writeln(OutputLine); 81 | p.WaitOnExit; 82 | Result := p.ExitStatus = 0; 83 | if not Result then 84 | Writeln('Command ', p.Executable ,' failed with exit code: ', p.ExitStatus); 85 | finally 86 | FreeAndNil(p); 87 | end; 88 | end; 89 | 90 | const 91 | {$ifdef MSWINDOWS}prog = 'cmd';{$endif} 92 | 93 | {$ifdef MACOS}prog = 'ls';{$endif} 94 | 95 | var args: TStringList; 96 | 97 | {$ifdef MSWINDOWS} 98 | procedure SetArgs; 99 | begin 100 | args.add('/c'); 101 | args.add('dir'); 102 | end; 103 | {$endif} 104 | 105 | {$ifdef MACOS} 106 | procedure SetArgs; 107 | begin 108 | // does LS require launching shell (sh) ?? 109 | end; 110 | {$endif} 111 | 112 | begin 113 | args := TStringList.Create; 114 | SetArgs; 115 | RunProcess(prog, args); 116 | args.free; args := nil; 117 | writeln('press enter to exit'); 118 | readln; 119 | end. 120 | -------------------------------------------------------------------------------- /demo2/demo2.dproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {ECD9A7BC-554D-4A45-9943-693A606558FB} 4 | 18.2 5 | None 6 | demo2.dpr 7 | True 8 | Debug 9 | Win32 10 | 1 11 | Console 12 | 13 | 14 | true 15 | 16 | 17 | true 18 | Base 19 | true 20 | 21 | 22 | true 23 | Base 24 | true 25 | 26 | 27 | true 28 | Base 29 | true 30 | 31 | 32 | true 33 | Base 34 | true 35 | 36 | 37 | true 38 | Cfg_1 39 | true 40 | true 41 | 42 | 43 | true 44 | Base 45 | true 46 | 47 | 48 | .\$(Platform)\$(Config) 49 | .\$(Platform)\$(Config) 50 | false 51 | false 52 | false 53 | false 54 | false 55 | RESTComponents;FireDAC;FireDACSqliteDriver;soaprtl;FireDACIBDriver;soapmidas;FireDACCommon;RESTBackendComponents;soapserver;CloudService;FireDACCommonDriver;inet;$(DCC_UsePackage) 56 | System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace) 57 | demo2 58 | 59 | 60 | DBXSqliteDriver;IndyIPCommon;bindcompdbx;DBXInterBaseDriver;IndyIPServer;IndySystem;tethering;fmxFireDAC;bindcompfmx;FireDACPgDriver;inetdb;DbxCommonDriver;fmx;fmxdae;xmlrtl;fmxobj;rtl;DbxClientDriver;CustomIPTransport;dbexpress;IndyCore;bindcomp;dsnap;IndyIPClient;dbxcds;bindengine;DBXMySQLDriver;dsnapxml;FireDACMySQLDriver;dbrtl;IndyProtocols;inetdbxpress;FireDACCommonODBC;fmxase;$(DCC_UsePackage) 61 | true 62 | 63 | 64 | DBXSqliteDriver;IndyIPCommon;bindcompdbx;DBXInterBaseDriver;vcl;IndyIPServer;vclactnband;DSPack_Tokyo;vclFireDAC;IndySystem;tethering;svnui;dsnapcon;FireDACADSDriver;FireDACMSAccDriver;fmxFireDAC;vclimg;vcltouch;vcldb;bindcompfmx;svn;FireDACPgDriver;inetdb;DbxCommonDriver;fmx;fmxdae;xmlrtl;fmxobj;vclwinx;rtl;DbxClientDriver;DCEF_Tokyo1;CustomIPTransport;vcldsnap;dbexpress;IndyCore;vclx;bindcomp;appanalytics;dsnap;IndyIPClient;bindcompvcl;VCLRESTComponents;dbxcds;VclSmp;adortl;vclie;bindengine;DBXMySQLDriver;dsnapxml;FireDACMySQLDriver;dbrtl;IndyProtocols;inetdbxpress;FireDACCommonODBC;fmxase;$(DCC_UsePackage) 65 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) 66 | Debug 67 | CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= 68 | 1033 69 | true 70 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png 71 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png 72 | 73 | 74 | DBXSqliteDriver;IndyIPCommon;bindcompdbx;DBXInterBaseDriver;vcl;IndyIPServer;vclactnband;vclFireDAC;IndySystem;tethering;dsnapcon;FireDACADSDriver;FireDACMSAccDriver;fmxFireDAC;vclimg;vcltouch;vcldb;bindcompfmx;FireDACPgDriver;inetdb;DbxCommonDriver;fmx;fmxdae;xmlrtl;fmxobj;vclwinx;rtl;DbxClientDriver;CustomIPTransport;vcldsnap;dbexpress;IndyCore;vclx;bindcomp;appanalytics;dsnap;IndyIPClient;bindcompvcl;VCLRESTComponents;dbxcds;VclSmp;adortl;vclie;bindengine;DBXMySQLDriver;dsnapxml;FireDACMySQLDriver;dbrtl;IndyProtocols;inetdbxpress;FireDACCommonODBC;fmxase;$(DCC_UsePackage) 75 | true 76 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png 77 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png 78 | 79 | 80 | DEBUG;$(DCC_Define) 81 | true 82 | false 83 | true 84 | true 85 | true 86 | 87 | 88 | false 89 | ..\;$(DCC_UnitSearchPath) 90 | 1033 91 | (None) 92 | 93 | 94 | false 95 | RELEASE;$(DCC_Define) 96 | 0 97 | 0 98 | 99 | 100 | 101 | MainSource 102 | 103 | 104 | Cfg_2 105 | Base 106 | 107 | 108 | Base 109 | 110 | 111 | Cfg_1 112 | Base 113 | 114 | 115 | 116 | Delphi.Personality.12 117 | Application 118 | 119 | 120 | 121 | demo2.dpr 122 | 123 | 124 | Microsoft Office 2000 Sample Automation Server Wrapper Components 125 | Microsoft Office XP Sample Automation Server Wrapper Components 126 | 127 | 128 | 129 | 130 | 131 | true 132 | 133 | 134 | 135 | 136 | true 137 | 138 | 139 | 140 | 141 | true 142 | 143 | 144 | 145 | 146 | true 147 | 148 | 149 | 150 | 151 | demo2.exe 152 | true 153 | 154 | 155 | 156 | 157 | 1 158 | 159 | 160 | Contents\MacOS 161 | 1 162 | 163 | 164 | Contents\MacOS 165 | 0 166 | 167 | 168 | 169 | 170 | classes 171 | 1 172 | 173 | 174 | 175 | 176 | library\lib\armeabi-v7a 177 | 1 178 | 179 | 180 | 181 | 182 | library\lib\armeabi 183 | 1 184 | 185 | 186 | 187 | 188 | library\lib\mips 189 | 1 190 | 191 | 192 | 193 | 194 | library\lib\armeabi-v7a 195 | 1 196 | 197 | 198 | 199 | 200 | res\drawable 201 | 1 202 | 203 | 204 | 205 | 206 | res\values 207 | 1 208 | 209 | 210 | 211 | 212 | res\drawable 213 | 1 214 | 215 | 216 | 217 | 218 | res\drawable-xxhdpi 219 | 1 220 | 221 | 222 | 223 | 224 | res\drawable-ldpi 225 | 1 226 | 227 | 228 | 229 | 230 | res\drawable-mdpi 231 | 1 232 | 233 | 234 | 235 | 236 | res\drawable-hdpi 237 | 1 238 | 239 | 240 | 241 | 242 | res\drawable-xhdpi 243 | 1 244 | 245 | 246 | 247 | 248 | res\drawable-small 249 | 1 250 | 251 | 252 | 253 | 254 | res\drawable-normal 255 | 1 256 | 257 | 258 | 259 | 260 | res\drawable-large 261 | 1 262 | 263 | 264 | 265 | 266 | res\drawable-xlarge 267 | 1 268 | 269 | 270 | 271 | 272 | 1 273 | 274 | 275 | Contents\MacOS 276 | 1 277 | 278 | 279 | 0 280 | 281 | 282 | 283 | 284 | Contents\MacOS 285 | 1 286 | .framework 287 | 288 | 289 | 0 290 | 291 | 292 | 293 | 294 | 1 295 | .dylib 296 | 297 | 298 | 1 299 | .dylib 300 | 301 | 302 | 1 303 | .dylib 304 | 305 | 306 | Contents\MacOS 307 | 1 308 | .dylib 309 | 310 | 311 | 0 312 | .dll;.bpl 313 | 314 | 315 | 316 | 317 | 1 318 | .dylib 319 | 320 | 321 | 1 322 | .dylib 323 | 324 | 325 | 1 326 | .dylib 327 | 328 | 329 | Contents\MacOS 330 | 1 331 | .dylib 332 | 333 | 334 | 0 335 | .bpl 336 | 337 | 338 | 339 | 340 | 0 341 | 342 | 343 | 0 344 | 345 | 346 | 0 347 | 348 | 349 | 0 350 | 351 | 352 | Contents\Resources\StartUp\ 353 | 0 354 | 355 | 356 | 0 357 | 358 | 359 | 360 | 361 | 1 362 | 363 | 364 | 1 365 | 366 | 367 | 1 368 | 369 | 370 | 371 | 372 | 1 373 | 374 | 375 | 1 376 | 377 | 378 | 1 379 | 380 | 381 | 382 | 383 | 1 384 | 385 | 386 | 1 387 | 388 | 389 | 1 390 | 391 | 392 | 393 | 394 | 1 395 | 396 | 397 | 1 398 | 399 | 400 | 1 401 | 402 | 403 | 404 | 405 | 1 406 | 407 | 408 | 1 409 | 410 | 411 | 1 412 | 413 | 414 | 415 | 416 | 1 417 | 418 | 419 | 1 420 | 421 | 422 | 1 423 | 424 | 425 | 426 | 427 | 1 428 | 429 | 430 | 1 431 | 432 | 433 | 1 434 | 435 | 436 | 437 | 438 | 1 439 | 440 | 441 | 442 | 443 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 444 | 1 445 | 446 | 447 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 448 | 1 449 | 450 | 451 | 452 | 453 | 1 454 | 455 | 456 | 1 457 | 458 | 459 | 460 | 461 | ..\ 462 | 1 463 | 464 | 465 | ..\ 466 | 1 467 | 468 | 469 | 470 | 471 | 1 472 | 473 | 474 | 1 475 | 476 | 477 | 1 478 | 479 | 480 | 481 | 482 | 1 483 | 484 | 485 | 1 486 | 487 | 488 | 1 489 | 490 | 491 | 492 | 493 | ..\ 494 | 1 495 | 496 | 497 | 498 | 499 | Contents 500 | 1 501 | 502 | 503 | 504 | 505 | Contents\Resources 506 | 1 507 | 508 | 509 | 510 | 511 | library\lib\armeabi-v7a 512 | 1 513 | 514 | 515 | 1 516 | 517 | 518 | 1 519 | 520 | 521 | 1 522 | 523 | 524 | 1 525 | 526 | 527 | Contents\MacOS 528 | 1 529 | 530 | 531 | 0 532 | 533 | 534 | 535 | 536 | 1 537 | 538 | 539 | 1 540 | 541 | 542 | 543 | 544 | Assets 545 | 1 546 | 547 | 548 | Assets 549 | 1 550 | 551 | 552 | 553 | 554 | Assets 555 | 1 556 | 557 | 558 | Assets 559 | 1 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | False 573 | False 574 | True 575 | False 576 | 577 | 578 | 12 579 | 580 | 581 | 582 | 583 | 584 | -------------------------------------------------------------------------------- /demo3/Unit1.dfm: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 0 3 | Top = 0 4 | Caption = 'Form1' 5 | ClientHeight = 283 6 | ClientWidth = 611 7 | Color = clBtnFace 8 | Font.Charset = DEFAULT_CHARSET 9 | Font.Color = clWindowText 10 | Font.Height = -13 11 | Font.Name = 'Tahoma' 12 | Font.Style = [] 13 | OldCreateOrder = False 14 | PixelsPerInch = 120 15 | TextHeight = 16 16 | object Label1: TLabel 17 | Left = 16 18 | Top = 256 19 | Width = 441 20 | Height = 16 21 | Caption = 22 | 'This program captures the output of a console program, using TPr' + 23 | 'ocess' 24 | end 25 | object Memo1: TMemo 26 | Left = 8 27 | Top = 8 28 | Width = 601 29 | Height = 236 30 | Lines.Strings = ( 31 | 'Output:') 32 | ScrollBars = ssVertical 33 | TabOrder = 0 34 | end 35 | object Button1: TButton 36 | Left = 472 37 | Top = 250 38 | Width = 137 39 | Height = 25 40 | Caption = 'Run Command' 41 | TabOrder = 1 42 | OnClick = Button1Click 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /demo3/Unit1.pas: -------------------------------------------------------------------------------- 1 | { This delphi demo shows how to capture the output of a command using TProcess 2 | now ported to delphi, originally from the FPC RTL/FCL 3 | Example: capture output of "dir" command (list directory contents), or any 4 | other command 5 | 6 | License: this demo is MIT/BSD, dprocess/dpipes is permissive modified LGPL 7 | } 8 | 9 | unit Unit1; 10 | 11 | interface 12 | 13 | uses 14 | Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 15 | Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; 16 | 17 | type 18 | TForm1 = class(TForm) 19 | Memo1: TMemo; 20 | Button1: TButton; 21 | Label1: TLabel; 22 | procedure Button1Click(Sender: TObject); 23 | private 24 | { Private declarations } 25 | public 26 | { Public declarations } 27 | end; 28 | 29 | var 30 | Form1: TForm1; 31 | 32 | implementation 33 | 34 | {$R *.dfm} 35 | 36 | uses dprocess; // this is the TProcess unit from FPC, now ported to delphi 37 | 38 | procedure OutLn(s: string); overload; 39 | begin 40 | form1.memo1.lines.add(s); 41 | end; 42 | 43 | procedure OutLn(s: string; i: integer); overload; 44 | begin 45 | outln(s + inttostr(i)); 46 | end; 47 | 48 | procedure DoLog(s: string); 49 | begin 50 | OutLn('Log: '+s); 51 | end; 52 | 53 | function RunProcess(const Binary: string; args: TStrings): boolean; 54 | const 55 | BufSize = 1024; 56 | var 57 | p: TProcess; 58 | // Buf: string; // L505 note: must use ansistring 59 | Buf: ansistring; // 60 | Count: integer; 61 | i: integer; 62 | LineStart: integer; 63 | // OutputLine: string; //L505 note: must use ansistring 64 | OutputLine: ansistring; // 65 | 66 | begin 67 | p := TProcess.Create(nil); 68 | try 69 | p.Executable := Binary; 70 | 71 | p.Options := [poUsePipes, 72 | poStdErrToOutPut]; 73 | // p.CurrentDirectory := ExtractFilePath(p.Executable); 74 | p.ShowWindow := swoHIDE {ShowNormal}; 75 | 76 | p.Parameters.Assign(args); 77 | DoLog('Running command '+ p.Executable +' with arguments: '+ p.Parameters.Text); 78 | p.Execute; 79 | 80 | { Now process the output } 81 | OutputLine:=''; 82 | SetLength(Buf,BufSize); 83 | repeat 84 | if (p.Output<>nil) then 85 | begin 86 | // Count:=p.Output.Read(Buf[1],Length(Buf)); 87 | Count:=p.Output.Read(pchar(Buf)^, BufSize); //L505 changed to pchar because of unicodestring 88 | // outln('DEBUG: len buf: ', length(buf)); 89 | end 90 | else 91 | Count:=0; 92 | LineStart:=1; 93 | i:=1; 94 | while i<=Count do 95 | begin 96 | // L505 97 | //if Buf[i] in [#10,#13] then 98 | if CharInSet(Buf[i], [#10,#13]) then 99 | begin 100 | OutputLine:=OutputLine+Copy(Buf,LineStart,i-LineStart); 101 | outln(OutputLine); 102 | OutputLine:=''; 103 | // L505 104 | //if (iBuf[i+1]) then 105 | if (iBuf[i+1]) then 106 | inc(i); 107 | LineStart:=i+1; 108 | end; 109 | inc(i); 110 | end; 111 | OutputLine:=Copy(Buf,LineStart,Count-LineStart+1); 112 | until Count=0; 113 | if OutputLine <> '' then 114 | outln(OutputLine); 115 | // else 116 | // outln('DEBUG: empty line'); 117 | p.WaitOnExit; 118 | Result := p.ExitStatus = 0; 119 | if not Result then 120 | outln('Command '+ p.Executable +' failed with exit code: ', p.ExitStatus); 121 | finally 122 | FreeAndNil(p); 123 | end; 124 | end; 125 | 126 | const 127 | {$ifdef MSWINDOWS}prog = 'cmd';{$endif} 128 | 129 | {$ifdef MACOS}prog = 'ls';{$endif} 130 | 131 | var args: TStringList; 132 | 133 | {$ifdef MSWINDOWS} 134 | procedure SetArgs; 135 | begin 136 | args.add('/c'); 137 | args.add('dir'); 138 | end; 139 | {$endif} 140 | 141 | {$ifdef MACOS} 142 | procedure SetArgs; 143 | begin 144 | // does LS require launching shell (sh) ?? 145 | end; 146 | {$endif} 147 | 148 | procedure TForm1.Button1Click(Sender: TObject); 149 | begin 150 | args := TStringList.Create; 151 | SetArgs; 152 | RunProcess(prog, args); 153 | args.free; args := nil; 154 | end; 155 | 156 | end. 157 | -------------------------------------------------------------------------------- /demo3/demo3.dpr: -------------------------------------------------------------------------------- 1 | program demo3; 2 | 3 | uses 4 | Vcl.Forms, 5 | Unit1 in 'Unit1.pas' {Form1}; 6 | 7 | {$R *.res} 8 | 9 | begin 10 | Application.Initialize; 11 | Application.MainFormOnTaskbar := True; 12 | Application.CreateForm(TForm1, Form1); 13 | Application.Run; 14 | end. 15 | -------------------------------------------------------------------------------- /demo3/demo3.dproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {0952E51E-4ABC-4F65-BDC2-2041FD4B6007} 4 | 18.2 5 | VCL 6 | demo3.dpr 7 | True 8 | Debug 9 | Win32 10 | 1 11 | Application 12 | 13 | 14 | true 15 | 16 | 17 | true 18 | Base 19 | true 20 | 21 | 22 | true 23 | Base 24 | true 25 | 26 | 27 | true 28 | Base 29 | true 30 | 31 | 32 | true 33 | Cfg_1 34 | true 35 | true 36 | 37 | 38 | true 39 | Base 40 | true 41 | 42 | 43 | true 44 | Cfg_2 45 | true 46 | true 47 | 48 | 49 | .\$(Platform)\$(Config) 50 | .\$(Platform)\$(Config) 51 | false 52 | false 53 | false 54 | false 55 | false 56 | RESTComponents;FireDAC;FireDACSqliteDriver;soaprtl;FireDACIBDriver;soapmidas;FireDACCommon;RESTBackendComponents;soapserver;CloudService;FireDACCommonDriver;inet;$(DCC_UsePackage) 57 | System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) 58 | $(BDS)\bin\delphi_PROJECTICON.ico 59 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png 60 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png 61 | demo3 62 | 63 | 64 | DBXSqliteDriver;IndyIPCommon;bindcompdbx;DBXInterBaseDriver;vcl;IndyIPServer;vclactnband;DSPack_Tokyo;vclFireDAC;IndySystem;tethering;svnui;dsnapcon;FireDACADSDriver;FireDACMSAccDriver;fmxFireDAC;vclimg;vcltouch;vcldb;bindcompfmx;svn;FireDACPgDriver;inetdb;DbxCommonDriver;fmx;fmxdae;xmlrtl;fmxobj;vclwinx;rtl;DbxClientDriver;DCEF_Tokyo1;CustomIPTransport;vcldsnap;dbexpress;IndyCore;vclx;bindcomp;appanalytics;dsnap;IndyIPClient;bindcompvcl;VCLRESTComponents;dbxcds;VclSmp;adortl;vclie;bindengine;DBXMySQLDriver;dsnapxml;FireDACMySQLDriver;dbrtl;IndyProtocols;inetdbxpress;FireDACCommonODBC;fmxase;$(DCC_UsePackage) 65 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) 66 | Debug 67 | true 68 | CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= 69 | 1033 70 | $(BDS)\bin\default_app.manifest 71 | 72 | 73 | DBXSqliteDriver;IndyIPCommon;bindcompdbx;DBXInterBaseDriver;vcl;IndyIPServer;vclactnband;vclFireDAC;IndySystem;tethering;dsnapcon;FireDACADSDriver;FireDACMSAccDriver;fmxFireDAC;vclimg;vcltouch;vcldb;bindcompfmx;FireDACPgDriver;inetdb;DbxCommonDriver;fmx;fmxdae;xmlrtl;fmxobj;vclwinx;rtl;DbxClientDriver;CustomIPTransport;vcldsnap;dbexpress;IndyCore;vclx;bindcomp;appanalytics;dsnap;IndyIPClient;bindcompvcl;VCLRESTComponents;dbxcds;VclSmp;adortl;vclie;bindengine;DBXMySQLDriver;dsnapxml;FireDACMySQLDriver;dbrtl;IndyProtocols;inetdbxpress;FireDACCommonODBC;fmxase;$(DCC_UsePackage) 74 | 75 | 76 | DEBUG;$(DCC_Define) 77 | true 78 | false 79 | true 80 | true 81 | true 82 | 83 | 84 | false 85 | true 86 | true 87 | ..\;$(DCC_UnitSearchPath) 88 | true 89 | 1033 90 | 91 | 92 | false 93 | RELEASE;$(DCC_Define) 94 | 0 95 | 0 96 | 97 | 98 | true 99 | true 100 | 101 | 102 | 103 | MainSource 104 | 105 | 106 |
Form1
107 | dfm 108 |
109 | 110 | Cfg_2 111 | Base 112 | 113 | 114 | Base 115 | 116 | 117 | Cfg_1 118 | Base 119 | 120 |
121 | 122 | Delphi.Personality.12 123 | Application 124 | 125 | 126 | 127 | demo3.dpr 128 | 129 | 130 | Microsoft Office 2000 Sample Automation Server Wrapper Components 131 | Microsoft Office XP Sample Automation Server Wrapper Components 132 | 133 | 134 | 135 | 136 | 137 | demo3.exe 138 | true 139 | 140 | 141 | 142 | 143 | 1 144 | 145 | 146 | Contents\MacOS 147 | 1 148 | 149 | 150 | Contents\MacOS 151 | 0 152 | 153 | 154 | 155 | 156 | classes 157 | 1 158 | 159 | 160 | 161 | 162 | library\lib\armeabi-v7a 163 | 1 164 | 165 | 166 | 167 | 168 | library\lib\armeabi 169 | 1 170 | 171 | 172 | 173 | 174 | library\lib\mips 175 | 1 176 | 177 | 178 | 179 | 180 | library\lib\armeabi-v7a 181 | 1 182 | 183 | 184 | 185 | 186 | res\drawable 187 | 1 188 | 189 | 190 | 191 | 192 | res\values 193 | 1 194 | 195 | 196 | 197 | 198 | res\drawable 199 | 1 200 | 201 | 202 | 203 | 204 | res\drawable-xxhdpi 205 | 1 206 | 207 | 208 | 209 | 210 | res\drawable-ldpi 211 | 1 212 | 213 | 214 | 215 | 216 | res\drawable-mdpi 217 | 1 218 | 219 | 220 | 221 | 222 | res\drawable-hdpi 223 | 1 224 | 225 | 226 | 227 | 228 | res\drawable-xhdpi 229 | 1 230 | 231 | 232 | 233 | 234 | res\drawable-small 235 | 1 236 | 237 | 238 | 239 | 240 | res\drawable-normal 241 | 1 242 | 243 | 244 | 245 | 246 | res\drawable-large 247 | 1 248 | 249 | 250 | 251 | 252 | res\drawable-xlarge 253 | 1 254 | 255 | 256 | 257 | 258 | 1 259 | 260 | 261 | Contents\MacOS 262 | 1 263 | 264 | 265 | 0 266 | 267 | 268 | 269 | 270 | Contents\MacOS 271 | 1 272 | .framework 273 | 274 | 275 | 0 276 | 277 | 278 | 279 | 280 | 1 281 | .dylib 282 | 283 | 284 | 1 285 | .dylib 286 | 287 | 288 | 1 289 | .dylib 290 | 291 | 292 | Contents\MacOS 293 | 1 294 | .dylib 295 | 296 | 297 | 0 298 | .dll;.bpl 299 | 300 | 301 | 302 | 303 | 1 304 | .dylib 305 | 306 | 307 | 1 308 | .dylib 309 | 310 | 311 | 1 312 | .dylib 313 | 314 | 315 | Contents\MacOS 316 | 1 317 | .dylib 318 | 319 | 320 | 0 321 | .bpl 322 | 323 | 324 | 325 | 326 | 0 327 | 328 | 329 | 0 330 | 331 | 332 | 0 333 | 334 | 335 | 0 336 | 337 | 338 | Contents\Resources\StartUp\ 339 | 0 340 | 341 | 342 | 0 343 | 344 | 345 | 346 | 347 | 1 348 | 349 | 350 | 1 351 | 352 | 353 | 1 354 | 355 | 356 | 357 | 358 | 1 359 | 360 | 361 | 1 362 | 363 | 364 | 1 365 | 366 | 367 | 368 | 369 | 1 370 | 371 | 372 | 1 373 | 374 | 375 | 1 376 | 377 | 378 | 379 | 380 | 1 381 | 382 | 383 | 1 384 | 385 | 386 | 1 387 | 388 | 389 | 390 | 391 | 1 392 | 393 | 394 | 1 395 | 396 | 397 | 1 398 | 399 | 400 | 401 | 402 | 1 403 | 404 | 405 | 1 406 | 407 | 408 | 1 409 | 410 | 411 | 412 | 413 | 1 414 | 415 | 416 | 1 417 | 418 | 419 | 1 420 | 421 | 422 | 423 | 424 | 1 425 | 426 | 427 | 428 | 429 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 430 | 1 431 | 432 | 433 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 434 | 1 435 | 436 | 437 | 438 | 439 | 1 440 | 441 | 442 | 1 443 | 444 | 445 | 446 | 447 | ..\ 448 | 1 449 | 450 | 451 | ..\ 452 | 1 453 | 454 | 455 | 456 | 457 | 1 458 | 459 | 460 | 1 461 | 462 | 463 | 1 464 | 465 | 466 | 467 | 468 | 1 469 | 470 | 471 | 1 472 | 473 | 474 | 1 475 | 476 | 477 | 478 | 479 | ..\ 480 | 1 481 | 482 | 483 | 484 | 485 | Contents 486 | 1 487 | 488 | 489 | 490 | 491 | Contents\Resources 492 | 1 493 | 494 | 495 | 496 | 497 | library\lib\armeabi-v7a 498 | 1 499 | 500 | 501 | 1 502 | 503 | 504 | 1 505 | 506 | 507 | 1 508 | 509 | 510 | 1 511 | 512 | 513 | Contents\MacOS 514 | 1 515 | 516 | 517 | 0 518 | 519 | 520 | 521 | 522 | 1 523 | 524 | 525 | 1 526 | 527 | 528 | 529 | 530 | Assets 531 | 1 532 | 533 | 534 | Assets 535 | 1 536 | 537 | 538 | 539 | 540 | Assets 541 | 1 542 | 543 | 544 | Assets 545 | 1 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | True 559 | False 560 | 561 | 562 | 12 563 | 564 | 565 | 566 | 567 |
568 | -------------------------------------------------------------------------------- /dpipes.pas: -------------------------------------------------------------------------------- 1 | { Freepascal pipes unit converted to Delphi. 2 | 3 | License: FPC Modified LGPL (okay to use in commercial projects) 4 | 5 | Changes to the code marked with "L505" in comments } 6 | 7 | { 8 | This file is part of the Free Pascal run time library. 9 | Copyright (c) 1999-2000 by Michael Van Canneyt 10 | 11 | Implementation of pipe stream. 12 | 13 | See the file COPYING.FPC, included in this distribution, 14 | for details about the copyright. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | 20 | **********************************************************************} 21 | 22 | 23 | unit dpipes; 24 | 25 | interface 26 | 27 | uses 28 | system.types, // L505 29 | sysutils, Classes; 30 | 31 | type 32 | EPipeError = Class(EStreamError); 33 | EPipeSeek = Class(EPipeError); 34 | EPipeCreation = Class(EPipeError); 35 | 36 | { TInputPipeStream } 37 | 38 | TInputPipeStream = Class(THandleStream) 39 | Private 40 | FPos : Int64; 41 | function GetNumBytesAvailable: DWord; 42 | procedure WriteNotImplemented; // L505 43 | procedure FakeSeekForward(Offset: Int64; const Origin: TSeekOrigin; 44 | const Pos: Int64); // L505 45 | procedure DiscardLarge(Count: int64; const MaxBufferSize: Longint); // L505 46 | procedure Discard(const Count: Int64); // L505 47 | 48 | protected 49 | function GetPosition: Int64; // override; //L505 50 | procedure InvalidSeek; // override; //L505 51 | public 52 | destructor Destroy; override; 53 | Function Write (Const Buffer; Count : Longint) :Longint; Override; 54 | function Seek(const Offset: int64; Origin: TSeekOrigin): int64; override; 55 | Function Read (Var Buffer; Count : Longint) : longint; Override; 56 | property NumBytesAvailable: DWord read GetNumBytesAvailable; 57 | end; 58 | 59 | TOutputPipeStream = Class(THandleStream) 60 | Private 61 | procedure ReadNotImplemented; // L505 62 | procedure InvalidSeek; // L505 63 | Public 64 | destructor Destroy; override; 65 | function Seek(const Offset: int64; Origin: TSeekOrigin): int64; override; 66 | Function Read(Var Buffer; Count : Longint) : longint; Override; 67 | end; 68 | 69 | Function CreatePipeHandles (Var Inhandle,OutHandle : THandle; APipeBufferSize : Cardinal = 1024) : Boolean; 70 | Procedure CreatePipeStreams (Var InPipe : TInputPipeStream; 71 | Var OutPipe : TOutputPipeStream); 72 | 73 | Const EPipeMsg = 'Failed to create pipe.'; 74 | ENoSeekMsg = 'Cannot seek on pipes'; 75 | 76 | 77 | Implementation 78 | 79 | {$IFDEF MACOS} // L505 80 | {$i pipes_macos.inc} 81 | {$ENDIF} 82 | 83 | {$IFDEF MSWINDOWS} // L505 84 | {$i pipes_win.inc} 85 | {$ENDIF} 86 | 87 | 88 | Procedure CreatePipeStreams (Var InPipe : TInputPipeStream; 89 | Var OutPipe : TOutputPipeStream); 90 | Var InHandle,OutHandle: THandle; 91 | begin 92 | if CreatePipeHandles(InHandle, OutHandle) then 93 | begin 94 | InPipe:=TInputPipeStream.Create(InHandle); 95 | OutPipe:=TOutputPipeStream.Create(OutHandle); 96 | end 97 | Else 98 | Raise EPipeCreation.Create(EPipeMsg) 99 | end; 100 | 101 | destructor TInputPipeStream.Destroy; 102 | begin 103 | PipeClose(Handle); 104 | inherited; 105 | end; 106 | 107 | // L505 108 | procedure TInputPipeStream.DiscardLarge(Count: int64; const MaxBufferSize: Longint); 109 | var 110 | Buffer: array of Byte; 111 | begin 112 | if Count=0 then 113 | Exit; 114 | if Count>MaxBufferSize then 115 | SetLength(Buffer,MaxBufferSize) 116 | else 117 | SetLength(Buffer,Count); 118 | while (Count>=Length(Buffer)) do 119 | begin 120 | ReadBuffer(Buffer[0],Length(Buffer)); 121 | Dec(Count,Length(Buffer)); 122 | end; 123 | if Count>0 then 124 | ReadBuffer(Buffer[0],Count); 125 | end; 126 | 127 | // L505 128 | procedure TInputPipeStream.Discard(const Count: Int64); 129 | const 130 | CSmallSize =255; 131 | CLargeMaxBuffer =32*1024; // 32 KiB 132 | var 133 | Buffer: array[1..CSmallSize] of Byte; 134 | begin 135 | if Count=0 then 136 | Exit; 137 | if Count<=SizeOf(Buffer) then 138 | ReadBuffer(Buffer,Count) 139 | else 140 | DiscardLarge(Count,CLargeMaxBuffer); 141 | end; 142 | 143 | // L505 144 | procedure TInputPipeStream.FakeSeekForward(Offset: Int64; const Origin: TSeekOrigin; const Pos: Int64); 145 | //var 146 | // Buffer: Pointer; 147 | // BufferSize, i: LongInt; 148 | begin 149 | if Origin=soBeginning then 150 | Dec(Offset,Pos); 151 | if (Offset<0) or (Origin=soEnd) then 152 | InvalidSeek; 153 | if Offset>0 then 154 | Discard(Offset); 155 | end; 156 | 157 | // L505 158 | procedure TInputPipeStream.WriteNotImplemented; 159 | begin 160 | raise EStreamError.CreateFmt('Cannot write to this stream, not implemented', []); 161 | end; 162 | 163 | // L505 164 | procedure TOutputPipeStream.ReadNotImplemented; 165 | begin 166 | raise EStreamError.CreateFmt('Cannot read from this stream, not implemented', []); 167 | end; 168 | 169 | Function TInputPipeStream.Write(Const Buffer; Count : Longint) : longint; 170 | begin 171 | WriteNotImplemented; 172 | Result := 0; 173 | end; 174 | 175 | Function TInputPipeStream.Read(Var Buffer; Count : Longint) : longint; 176 | begin 177 | Result:=Inherited Read(Buffer,Count); 178 | Inc(FPos,Result); 179 | end; 180 | 181 | function TInputPipeStream.Seek(const Offset: int64; Origin: TSeekOrigin): int64; 182 | begin 183 | FakeSeekForward(Offset,Origin,FPos); 184 | Result:=FPos; 185 | end; 186 | 187 | destructor TOutputPipeStream.Destroy; 188 | begin 189 | PipeClose(Handle); 190 | inherited; 191 | end; 192 | 193 | Function TOutputPipeStream.Read(Var Buffer; Count : Longint) : longint; 194 | begin 195 | ReadNotImplemented; 196 | Result := 0; 197 | end; 198 | 199 | procedure TOutputPipeStream.InvalidSeek; 200 | begin 201 | raise EStreamError.CreateFmt('Invalid seek in TProcess', []); 202 | end; 203 | 204 | function TOutputPipeStream.Seek(const Offset: int64; Origin: TSeekOrigin): int64; 205 | begin 206 | Result:=0; { to silence warning mostly } 207 | InvalidSeek; 208 | end; 209 | 210 | end. 211 | -------------------------------------------------------------------------------- /dprocess.pas: -------------------------------------------------------------------------------- 1 | { Freepascal TProcess ported to Delphi 2 | 3 | License: FPC Modified LGPL (can use in commercial apps) 4 | 5 | Changes to the code marked with "L505" in comments } 6 | 7 | { 8 | This file is part of the Free Component Library (FCL) 9 | Copyright (c) 1999-2000 by the Free Pascal development team 10 | 11 | See the file COPYING.FPC, included in this distribution, 12 | for details about the copyright. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 | 18 | **********************************************************************} 19 | 20 | unit dprocess; 21 | 22 | interface 23 | 24 | uses 25 | classes, 26 | dpipes, // L505 27 | system.types,//L505 28 | sysutils; 29 | 30 | 31 | Type 32 | TProcessOption = (poRunSuspended,poWaitOnExit, 33 | poUsePipes,poStderrToOutPut, 34 | poNoConsole,poNewConsole, 35 | poDefaultErrorMode,poNewProcessGroup, 36 | poDebugProcess,poDebugOnlyThisProcess); 37 | 38 | TShowWindowOptions = (swoNone,swoHIDE,swoMaximize,swoMinimize,swoRestore,swoShow, 39 | swoShowDefault,swoShowMaximized,swoShowMinimized, 40 | swoshowMinNOActive,swoShowNA,swoShowNoActivate,swoShowNormal); 41 | 42 | TStartupOption = (suoUseShowWindow,suoUseSize,suoUsePosition, 43 | suoUseCountChars,suoUseFillAttribute); 44 | 45 | TProcessPriority = (ppHigh,ppIdle,ppNormal,ppRealTime); 46 | 47 | TProcessOptions = set of TProcessOption; 48 | TStartupOptions = set of TStartupOption; 49 | 50 | 51 | Type 52 | {$ifdef MACOS} //L505 53 | TProcessForkEvent = procedure(Sender : TObject) of object; 54 | {$endif} 55 | 56 | { TProcess } 57 | 58 | TProcess = Class (TComponent) 59 | Private 60 | FProcessOptions : TProcessOptions; 61 | FStartupOptions : TStartupOptions; 62 | FProcessID : Integer; 63 | FTerminalProgram: String; 64 | FThreadID : Integer; 65 | FProcessHandle : Thandle; 66 | FThreadHandle : Thandle; 67 | FFillAttribute : Cardinal; 68 | FApplicationName : string; 69 | FConsoleTitle : String; 70 | FCommandLine : String; 71 | FCurrentDirectory : String; 72 | FDesktop : String; 73 | FEnvironment : Tstrings; 74 | FExecutable : String; 75 | FParameters : TStrings; 76 | FShowWindow : TShowWindowOptions; 77 | FInherithandles : Boolean; 78 | {$ifdef MACOS} // L505 79 | FForkEvent : TProcessForkEvent; 80 | {$endif} 81 | FProcessPriority : TProcessPriority; 82 | dwXCountchars, 83 | dwXSize, 84 | dwYsize, 85 | dwx, 86 | dwYcountChars, 87 | dwy : Cardinal; 88 | FXTermProgram: String; 89 | FPipeBufferSize : cardinal; 90 | Procedure FreeStreams; 91 | Function GetExitStatus : Integer; 92 | Function GetExitCode : Integer; 93 | Function GetRunning : Boolean; 94 | Function GetWindowRect : TRect; 95 | procedure SetCommandLine(const AValue: String); 96 | procedure SetParameters(const AValue: TStrings); 97 | Procedure SetWindowRect (Value : TRect); 98 | Procedure SetShowWindow (Value : TShowWindowOptions); 99 | Procedure SetWindowColumns (Value : Cardinal); 100 | Procedure SetWindowHeight (Value : Cardinal); 101 | Procedure SetWindowLeft (Value : Cardinal); 102 | Procedure SetWindowRows (Value : Cardinal); 103 | Procedure SetWindowTop (Value : Cardinal); 104 | Procedure SetWindowWidth (Value : Cardinal); 105 | procedure SetApplicationName(const Value: String); 106 | procedure SetProcessOptions(const Value: TProcessOptions); 107 | procedure SetActive(const Value: Boolean); 108 | procedure SetEnvironment(const Value: TStrings); 109 | Procedure ConvertCommandLine; 110 | function PeekExitStatus: Boolean; 111 | Protected 112 | FRunning : Boolean; 113 | FExitCode : Cardinal; 114 | FInputStream : TOutputPipeStream; 115 | FOutputStream : TInputPipeStream; 116 | FStderrStream : TInputPipeStream; 117 | procedure CloseProcessHandles; virtual; 118 | Procedure CreateStreams(InHandle,OutHandle,ErrHandle : Longint);virtual; 119 | procedure FreeStream(var AStream: THandleStream); 120 | procedure Loaded; override; 121 | Public 122 | Constructor Create (AOwner : TComponent);override; 123 | Destructor Destroy; override; 124 | Procedure Execute; virtual; 125 | procedure CloseInput; virtual; 126 | procedure CloseOutput; virtual; 127 | procedure CloseStderr; virtual; 128 | Function Resume : Integer; virtual; 129 | Function Suspend : Integer; virtual; 130 | Function Terminate (AExitCode : Integer): Boolean; virtual; 131 | Function WaitOnExit : Boolean; 132 | Property WindowRect : Trect Read GetWindowRect Write SetWindowRect; 133 | Property Handle : THandle Read FProcessHandle; 134 | Property ProcessHandle : THandle Read FProcessHandle; 135 | Property ThreadHandle : THandle Read FThreadHandle; 136 | Property ProcessID : Integer Read FProcessID; 137 | Property ThreadID : Integer Read FThreadID; 138 | Property Input : TOutputPipeStream Read FInputStream; 139 | Property Output : TInputPipeStream Read FOutputStream; 140 | Property Stderr : TinputPipeStream Read FStderrStream; 141 | Property ExitStatus : Integer Read GetExitStatus; 142 | Property ExitCode : Integer Read GetExitCode; 143 | Property InheritHandles : Boolean Read FInheritHandles Write FInheritHandles; 144 | {$ifdef MACOS} // L505 145 | property OnForkEvent : TProcessForkEvent Read FForkEvent Write FForkEvent; 146 | {$endif} 147 | Published 148 | property PipeBufferSize : cardinal read FPipeBufferSize write FPipeBufferSize default 1024; 149 | Property Active : Boolean Read GetRunning Write SetActive; 150 | Property ApplicationName : String Read FApplicationName Write SetApplicationName; //deprecated; //L505 151 | Property CommandLine : String Read FCommandLine Write SetCommandLine ; //deprecated; //L505 152 | Property Executable : String Read FExecutable Write FExecutable; 153 | Property Parameters : TStrings Read FParameters Write SetParameters; 154 | Property ConsoleTitle : String Read FConsoleTitle Write FConsoleTitle; 155 | Property CurrentDirectory : String Read FCurrentDirectory Write FCurrentDirectory; 156 | Property Desktop : String Read FDesktop Write FDesktop; 157 | Property Environment : TStrings Read FEnvironment Write SetEnvironment; 158 | Property Options : TProcessOptions Read FProcessOptions Write SetProcessOptions; 159 | Property Priority : TProcessPriority Read FProcessPriority Write FProcessPriority; 160 | Property StartupOptions : TStartupOptions Read FStartupOptions Write FStartupOptions; 161 | Property Running : Boolean Read GetRunning; 162 | Property ShowWindow : TShowWindowOptions Read FShowWindow Write SetShowWindow; 163 | Property WindowColumns : Cardinal Read dwXCountChars Write SetWindowColumns; 164 | Property WindowHeight : Cardinal Read dwYSize Write SetWindowHeight; 165 | Property WindowLeft : Cardinal Read dwX Write SetWindowLeft; 166 | Property WindowRows : Cardinal Read dwYCountChars Write SetWindowRows; 167 | Property WindowTop : Cardinal Read dwY Write SetWindowTop ; 168 | Property WindowWidth : Cardinal Read dwXSize Write SetWindowWidth; 169 | Property FillAttribute : Cardinal read FFillAttribute Write FFillAttribute; 170 | Property XTermProgram : String Read FXTermProgram Write FXTermProgram; 171 | end; 172 | 173 | EProcess = Class(Exception); 174 | 175 | Procedure CommandToList(S : String; List : TStrings); 176 | 177 | {$ifdef MACOS} //L505 178 | Var 179 | TryTerminals : Array of string; 180 | XTermProgram : String; 181 | Function DetectXTerm : String; 182 | {$endif} 183 | 184 | { // L505: changed to ansistring 185 | function RunCommandIndir(const curdir:string;const exename:string;const commands:array of string;out outputstring:string; out exitstatus:integer; Options : TProcessOptions = []):integer; overload; //L505 186 | function RunCommandIndir(const curdir:string;const exename:string;const commands:array of string;out outputstring:string; Options : TProcessOptions = []):boolean; overload; // L505 187 | function RunCommand(const exename:string;const commands:array of string;out outputstring:string; Options : TProcessOptions = []):boolean; overload;// L505 188 | 189 | 190 | function RunCommandInDir(const curdir,cmdline:string;out outputstring:string):boolean; deprecated; overload; // L505 191 | function RunCommand(const cmdline:string;out outputstring:string):boolean; deprecated; overload; // L505 192 | } 193 | 194 | function RunCommandIndir(const curdir: string; const exename: string; const commands: array of string; out outputstring: ansistring; out exitstatus:integer; Options : TProcessOptions = []):integer; overload; //L505 195 | function RunCommandIndir(const curdir: string; const exename: string; const commands: array of string; out outputstring: ansistring; Options : TProcessOptions = []):boolean; overload; // L505 196 | function RunCommand(const exename: string; const commands: array of string; out outputstring: ansistring; Options : TProcessOptions = []):boolean; overload;// L505 197 | 198 | 199 | function RunCommandInDir(const curdir,cmdline:string;out outputstring:ansistring):boolean; deprecated; overload; // L505 200 | function RunCommand(const cmdline:string;out outputstring:ansistring):boolean; deprecated; overload; // L505 201 | 202 | 203 | implementation 204 | 205 | {$IFDEF MACOS} //L505 206 | {$i process_macos.inc} 207 | {$ENDIF} 208 | 209 | {$IFDEF MSWINDOWS} //L505 210 | {$i process_win.inc} 211 | {$ENDIF} 212 | 213 | Procedure CommandToList(S : String; List : TStrings); 214 | 215 | Function GetNextWord : String; 216 | 217 | Const 218 | WhiteSpace = [' ',#9,#10,#13]; 219 | Literals = ['"','''']; 220 | 221 | Var 222 | Wstart,wend : Integer; 223 | InLiteral : Boolean; 224 | LastLiteral : char; 225 | 226 | begin 227 | WStart:=1; 228 | // L505 change "in" to CharInSet 229 | While (WStart<=Length(S)) and (CharInSet(S[WStart], WhiteSpace)) do 230 | Inc(WStart); 231 | WEnd:=WStart; 232 | InLiteral:=False; 233 | LastLiteral:=#0; 234 | // L505 235 | // While (Wend<=Length(S)) and (Not (S[Wend] in WhiteSpace) or InLiteral) do 236 | While (Wend<=Length(S)) and (Not (CharInSet(S[Wend], WhiteSpace)) or InLiteral) do 237 | begin 238 | // L505 changed "in" to CharInSet 239 | if CharInSet(S[Wend], Literals) then 240 | If InLiteral then 241 | InLiteral:=Not (S[Wend]=LastLiteral) 242 | else 243 | begin 244 | InLiteral:=True; 245 | LastLiteral:=S[Wend]; 246 | end; 247 | inc(wend); 248 | end; 249 | 250 | Result:=Copy(S,WStart,WEnd-WStart); 251 | // L505 changed "in" to CharInSet 252 | if (Length(Result) > 0) 253 | and (Result[1] = Result[Length(Result)]) // if 1st char = last char and.. 254 | and (CharInSet(Result[1], Literals)) then // it's one of the literals, then 255 | Result:=Copy(Result, 2, Length(Result) - 2); //delete the 2 (but not others in it) 256 | // L505 257 | // While (WEnd<=Length(S)) and (S[Wend] in WhiteSpace) do 258 | While (WEnd<=Length(S)) and (CharInSet(S[Wend], WhiteSpace)) do 259 | inc(Wend); 260 | Delete(S,1,WEnd-1); 261 | 262 | end; 263 | 264 | Var 265 | W : String; 266 | 267 | begin 268 | While Length(S)>0 do 269 | begin 270 | W:=GetNextWord; 271 | If (W<>'') then 272 | List.Add(W); 273 | end; 274 | end; 275 | 276 | Constructor TProcess.Create (AOwner : TComponent); 277 | begin 278 | Inherited; 279 | FProcessPriority:=ppNormal; 280 | FShowWindow:=swoNone; 281 | FInheritHandles:=True; 282 | {$ifdef MACOS} // L505 283 | FForkEvent:=nil; 284 | {$endif} 285 | FPipeBufferSize := 1024; 286 | FEnvironment:=TStringList.Create; 287 | FParameters:=TStringList.Create; 288 | end; 289 | 290 | Destructor TProcess.Destroy; 291 | begin 292 | FParameters.Free; 293 | FEnvironment.Free; 294 | FreeStreams; 295 | CloseProcessHandles; 296 | Inherited Destroy; 297 | end; 298 | 299 | Procedure TProcess.FreeStreams; 300 | begin 301 | If FStderrStream<>FOutputStream then 302 | FreeStream(THandleStream(FStderrStream)); 303 | FreeStream(THandleStream(FOutputStream)); 304 | FreeStream(THandleStream(FInputStream)); 305 | end; 306 | 307 | Function TProcess.GetExitStatus : Integer; 308 | begin 309 | GetRunning; 310 | Result:=FExitCode; 311 | end; 312 | 313 | {$IFNDEF OS_HASEXITCODE} 314 | Function TProcess.GetExitCode : Integer; 315 | begin 316 | if Not Running then 317 | Result:=GetExitStatus 318 | else 319 | Result:=0 320 | end; 321 | {$ENDIF} 322 | 323 | Function TProcess.GetRunning : Boolean; 324 | begin 325 | IF FRunning then 326 | FRunning:=Not PeekExitStatus; 327 | Result:=FRunning; 328 | end; 329 | 330 | Procedure TProcess.CreateStreams(InHandle,OutHandle,ErrHandle : Longint); 331 | 332 | begin 333 | FreeStreams; 334 | FInputStream:=TOutputPipeStream.Create (InHandle); 335 | FOutputStream:=TInputPipeStream.Create (OutHandle); 336 | if Not (poStderrToOutput in FProcessOptions) then 337 | FStderrStream:=TInputPipeStream.Create(ErrHandle); 338 | end; 339 | 340 | procedure TProcess.FreeStream(var AStream: THandleStream); 341 | begin 342 | if AStream = nil then exit; 343 | FreeAndNil(AStream); 344 | end; 345 | 346 | procedure TProcess.Loaded; 347 | begin 348 | inherited Loaded; 349 | If (csDesigning in ComponentState) and (FCommandLine<>'') then 350 | ConvertCommandLine; 351 | end; 352 | 353 | procedure TProcess.CloseInput; 354 | begin 355 | FreeStream(THandleStream(FInputStream)); 356 | end; 357 | 358 | procedure TProcess.CloseOutput; 359 | begin 360 | FreeStream(THandleStream(FOutputStream)); 361 | end; 362 | 363 | procedure TProcess.CloseStderr; 364 | begin 365 | FreeStream(THandleStream(FStderrStream)); 366 | end; 367 | 368 | Procedure TProcess.SetWindowColumns (Value : Cardinal); 369 | begin 370 | if Value<>0 then 371 | Include(FStartupOptions,suoUseCountChars); 372 | dwXCountChars:=Value; 373 | end; 374 | 375 | 376 | Procedure TProcess.SetWindowHeight (Value : Cardinal); 377 | begin 378 | if Value<>0 then 379 | include(FStartupOptions,suoUsePosition); 380 | dwYSize:=Value; 381 | end; 382 | 383 | Procedure TProcess.SetWindowLeft (Value : Cardinal); 384 | begin 385 | if Value<>0 then 386 | Include(FStartupOptions,suoUseSize); 387 | dwx:=Value; 388 | end; 389 | 390 | Procedure TProcess.SetWindowTop (Value : Cardinal); 391 | begin 392 | if Value<>0 then 393 | Include(FStartupOptions,suoUsePosition); 394 | dwy:=Value; 395 | end; 396 | 397 | Procedure TProcess.SetWindowWidth (Value : Cardinal); 398 | begin 399 | If (Value<>0) then 400 | Include(FStartupOptions,suoUseSize); 401 | dwXSize:=Value; 402 | end; 403 | 404 | Function TProcess.GetWindowRect : TRect; 405 | begin 406 | With Result do 407 | begin 408 | Left:=dwx; 409 | Right:=dwx+dwxSize; 410 | Top:=dwy; 411 | Bottom:=dwy+dwysize; 412 | end; 413 | end; 414 | 415 | procedure TProcess.SetCommandLine(const AValue: String); 416 | begin 417 | if FCommandLine=AValue then exit; 418 | FCommandLine:=AValue; 419 | If Not (csLoading in ComponentState) then 420 | ConvertCommandLine; 421 | end; 422 | 423 | procedure TProcess.SetParameters(const AValue: TStrings); 424 | begin 425 | FParameters.Assign(AValue); 426 | end; 427 | 428 | Procedure TProcess.SetWindowRect (Value : Trect); 429 | begin 430 | Include(FStartupOptions,suoUseSize); 431 | Include(FStartupOptions,suoUsePosition); 432 | With Value do 433 | begin 434 | dwx:=Left; 435 | dwxSize:=Right-Left; 436 | dwy:=Top; 437 | dwySize:=Bottom-top; 438 | end; 439 | end; 440 | 441 | Procedure TProcess.SetWindowRows (Value : Cardinal); 442 | begin 443 | if Value<>0 then 444 | Include(FStartupOptions,suoUseCountChars); 445 | dwYCountChars:=Value; 446 | end; 447 | 448 | procedure TProcess.SetApplicationName(const Value: String); 449 | begin 450 | FApplicationName := Value; 451 | If (csDesigning in ComponentState) and 452 | (FCommandLine='') then 453 | FCommandLine:=Value; 454 | end; 455 | 456 | procedure TProcess.SetProcessOptions(const Value: TProcessOptions); 457 | begin 458 | FProcessOptions := Value; 459 | If poNewConsole in FProcessOptions then 460 | Exclude(FProcessOptions,poNoConsole); 461 | if poRunSuspended in FProcessOptions then 462 | Exclude(FProcessOptions,poWaitOnExit); 463 | end; 464 | 465 | procedure TProcess.SetActive(const Value: Boolean); 466 | begin 467 | if (Value<>GetRunning) then 468 | If Value then 469 | Execute 470 | else 471 | Terminate(0); 472 | end; 473 | 474 | procedure TProcess.SetEnvironment(const Value: TStrings); 475 | begin 476 | FEnvironment.Assign(Value); 477 | end; 478 | 479 | procedure TProcess.ConvertCommandLine; 480 | begin 481 | FParameters.Clear; 482 | CommandToList(FCommandLine,FParameters); 483 | If FParameters.Count>0 then 484 | begin 485 | Executable:=FParameters[0]; 486 | FParameters.Delete(0); 487 | end; 488 | end; 489 | 490 | Const 491 | READ_BYTES = 65536; // not too small to avoid fragmentation when reading large files. 492 | 493 | // helperfunction that does the bulk of the work. 494 | // We need to also collect stderr output in order to avoid 495 | // lock out if the stderr pipe is full. 496 | // L505: changed to ansistring 497 | // function internalRuncommand(p:TProcess;out outputstring: string; 498 | // out stderrstring: string; out exitstatus:integer):integer; 499 | function internalRuncommand(p:TProcess;out outputstring: ansistring; 500 | out stderrstring: ansistring; out exitstatus:integer):integer; 501 | var 502 | numbytes,bytesread,available : integer; 503 | outputlength, stderrlength : integer; 504 | stderrnumbytes,stderrbytesread : integer; 505 | begin 506 | result:=-1; 507 | bytesread:=0; 508 | outputlength:=0; 509 | stderrbytesread:=0; 510 | stderrlength:=0; 511 | 512 | try 513 | try 514 | p.Options := p.Options + [poUsePipes]; 515 | p.Execute; 516 | 517 | while p.Running do 518 | begin 519 | // Only call ReadFromStream if Data from corresponding stream 520 | // is already available, otherwise, on linux, the read call 521 | // is blocking, and thus it is not possible to be sure to handle 522 | // big data amounts bboth on output and stderr pipes. PM. 523 | available:=P.Output.NumBytesAvailable; 524 | // writeln('DEBUG: bytesavail: ', P.Output.NumBytesAvailable); 525 | if available > 0 then 526 | begin 527 | if (BytesRead + available > outputlength) then 528 | begin 529 | outputlength:=BytesRead + READ_BYTES; 530 | Setlength(outputstring,outputlength); 531 | end; 532 | NumBytes := p.Output.Read(outputstring[1+bytesread], available); 533 | // L505 if in the future above string is unicodestring, above may need work NOTE: pchar is zero based . http://docwiki.embarcadero.com/RADStudio/Seattle/en/Using_Streams_to_Read_or_Write_Data 534 | // NumBytes := p.Output.Read(pchar(outputstring)[bytesread], available); 535 | 536 | if NumBytes > 0 then 537 | Inc(BytesRead, NumBytes); 538 | end 539 | // The check for assigned(P.stderr) is mainly here so that 540 | // if we use poStderrToOutput in p.Options, we do not access invalid memory. 541 | else if assigned(P.stderr) and (P.StdErr.NumBytesAvailable > 0) then 542 | begin 543 | available:=P.StdErr.NumBytesAvailable; 544 | if (StderrBytesRead + available > stderrlength) then 545 | begin 546 | stderrlength:=StderrBytesRead + READ_BYTES; 547 | Setlength(stderrstring,stderrlength); 548 | end; 549 | StderrNumBytes := p.StdErr.Read(stderrstring[1+StderrBytesRead], available); 550 | // L505 in the future if the above is a unicodestring this may need work, and NOTE: pchar is zero based 551 | // StderrNumBytes := p.StdErr.Read(pchar(stderrstring)[StderrBytesRead], available); 552 | 553 | if StderrNumBytes > 0 then 554 | Inc(StderrBytesRead, StderrNumBytes); 555 | end 556 | else 557 | Sleep(100); 558 | end; 559 | // Get left output after end of execution 560 | available:=P.Output.NumBytesAvailable; 561 | while available > 0 do 562 | begin 563 | if (BytesRead + available > outputlength) then 564 | begin 565 | outputlength:=BytesRead + READ_BYTES; 566 | Setlength(outputstring,outputlength); 567 | end; 568 | NumBytes := p.Output.Read(outputstring[1+bytesread], available); 569 | // L505 if above is unicodestring in the future it may need work, and NOTE: pchar is zero based 570 | // NumBytes := p.Output.Read(pchar(outputstring)[bytesread], available); 571 | 572 | if NumBytes > 0 then 573 | Inc(BytesRead, NumBytes); 574 | available:=P.Output.NumBytesAvailable; 575 | end; 576 | setlength(outputstring,BytesRead); 577 | while assigned(P.stderr) and (P.Stderr.NumBytesAvailable > 0) do 578 | begin 579 | available:=P.Stderr.NumBytesAvailable; 580 | if (StderrBytesRead + available > stderrlength) then 581 | begin 582 | stderrlength:=StderrBytesRead + READ_BYTES; 583 | Setlength(stderrstring,stderrlength); 584 | end; 585 | StderrNumBytes := p.StdErr.Read(stderrstring[1+StderrBytesRead], available); 586 | // L505 if above is unicodestring in the future, it may need work and NOTE: pchar is zero based 587 | // StderrNumBytes := p.StdErr.Read(pchar(stderrstring)[StderrBytesRead], available); 588 | 589 | if StderrNumBytes > 0 then 590 | Inc(StderrBytesRead, StderrNumBytes); 591 | end; 592 | setlength(stderrstring,StderrBytesRead); 593 | exitstatus:=p.exitstatus; 594 | result:=0; // we came to here, document that. 595 | except 596 | on e : Exception do 597 | begin 598 | result:=1; 599 | setlength(outputstring,BytesRead); 600 | end; 601 | end; 602 | finally 603 | p.free; 604 | end; 605 | end; 606 | 607 | { Functions without StderrString } 608 | 609 | Const 610 | ForbiddenOptions = [poRunSuspended,poWaitOnExit]; 611 | 612 | // L505 changed to ansistring 613 | // function RunCommandIndir(const curdir:string;const exename:string;const commands:array of string;out outputstring:string;out exitstatus:integer; Options : TProcessOptions = []):integer; 614 | function RunCommandIndir(const curdir: string; const exename: string; const commands:array of string; out outputstring: ansistring;out exitstatus:integer; Options : TProcessOptions = []):integer; 615 | Var 616 | p : TProcess; 617 | i : integer; 618 | // ErrorString : String; // L505 619 | ErrorString: ansistring; 620 | begin 621 | p:=TProcess.create(nil); 622 | if Options<>[] then 623 | P.Options:=Options - ForbiddenOptions; 624 | p.Executable:=exename; 625 | if curdir<>'' then 626 | p.CurrentDirectory:=curdir; 627 | if high(commands)>=0 then 628 | for i:=low(commands) to high(commands) do 629 | p.Parameters.add(commands[i]); 630 | result:=internalruncommand(p,outputstring,errorstring,exitstatus); 631 | end; 632 | 633 | // L505 changed to ansistring 634 | // function RunCommandInDir(const curdir,cmdline:string;out outputstring:string):boolean; deprecated; 635 | function RunCommandInDir(const curdir,cmdline:string;out outputstring: ansistring):boolean; deprecated; 636 | Var 637 | p : TProcess; 638 | exitstatus : integer; 639 | // ErrorString : String; // L505 640 | ErrorString: ansistring; // L505 641 | begin 642 | p:=TProcess.create(nil); 643 | p.setcommandline(cmdline); 644 | if curdir<>'' then 645 | p.CurrentDirectory:=curdir; 646 | result:=internalruncommand(p,outputstring,errorstring,exitstatus)=0; 647 | if exitstatus<>0 then result:=false; 648 | end; 649 | 650 | // L505 changed to ansistring 651 | // function RunCommandIndir(const curdir:string;const exename:string;const commands:array of string;out outputstring:string; Options : TProcessOptions = []):boolean; 652 | function RunCommandIndir(const curdir: string; const exename: string; const commands:array of string; out outputstring: ansistring; Options : TProcessOptions = []):boolean; 653 | Var 654 | p : TProcess; 655 | i, 656 | exitstatus : integer; 657 | // ErrorString : String; // L505 658 | ErrorString: ansistring; // L505 659 | begin 660 | p:=TProcess.create(nil); 661 | if Options<>[] then 662 | P.Options:=Options - ForbiddenOptions; 663 | p.Executable:=exename; 664 | if curdir<>'' then 665 | p.CurrentDirectory:=curdir; 666 | if high(commands)>=0 then 667 | for i:=low(commands) to high(commands) do 668 | p.Parameters.add(commands[i]); 669 | result:=internalruncommand(p,outputstring,errorstring,exitstatus)=0; 670 | if exitstatus<>0 then result:=false; 671 | end; 672 | 673 | // L505 changed to ansistring 674 | // function RunCommand(const cmdline:string; out outputstring:string):boolean; deprecated; 675 | function RunCommand(const cmdline: string; out outputstring: ansistring):boolean; deprecated; 676 | Var 677 | p : TProcess; 678 | exitstatus : integer; 679 | // ErrorString : String; // L505 680 | ErrorString: ansistring; // L505 681 | begin 682 | p:=TProcess.create(nil); 683 | p.setcommandline(cmdline); 684 | result:=internalruncommand(p,outputstring,errorstring,exitstatus)=0; 685 | if exitstatus<>0 then result:=false; 686 | end; 687 | 688 | // L505: Changed to ansistring 689 | // function RunCommand(const exename:string;const commands:array of string;out outputstring:string; Options : TProcessOptions = []):boolean; 690 | function RunCommand(const exename:string; const commands:array of string; out outputstring: ansistring; Options : TProcessOptions = []):boolean; 691 | Var 692 | p : TProcess; 693 | i, 694 | exitstatus : integer; 695 | // ErrorString : String; // L505 696 | ErrorString: ansistring; // L505 697 | begin 698 | p:=TProcess.create(nil); 699 | if Options<>[] then 700 | P.Options:=Options - ForbiddenOptions; 701 | p.Executable:=exename; 702 | if high(commands)>=0 then 703 | for i:=low(commands) to high(commands) do 704 | p.Parameters.add(commands[i]); 705 | result:=internalruncommand(p,outputstring,errorstring,exitstatus)=0; 706 | if exitstatus<>0 then result:=false; 707 | end; 708 | 709 | end. 710 | -------------------------------------------------------------------------------- /pipes_win.inc: -------------------------------------------------------------------------------- 1 | { Freepascal pipes unit converted to Delphi (needed for TProcess) 2 | 3 | License: FPC Modified LGPL (okay to use in commercial projects) 4 | 5 | Changes to the code marked with "L505" in comments } 6 | 7 | { 8 | This file is part of the Free Pascal run time library. 9 | Copyright (c) 1998 by Michael Van Canneyt 10 | 11 | Win part of pipe stream. 12 | 13 | See the file COPYING.FPC, included in this distribution, 14 | for details about the copyright. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | 20 | **********************************************************************} 21 | uses 22 | windows; //L505 23 | 24 | // L505 25 | type 26 | PSecurityAttributes = ^TSecurityAttributes; 27 | TSecurityAttributes = record 28 | nLength : DWORD; 29 | lpSecurityDescriptor : Pointer; 30 | bInheritHandle : BOOL; 31 | end; 32 | 33 | Const piInheritablePipe : TSecurityAttributes = ( 34 | nlength:SizeOF(TSecurityAttributes); 35 | lpSecurityDescriptor:Nil; 36 | Binherithandle:True); 37 | piNonInheritablePipe : TSecurityAttributes = ( 38 | nlength:SizeOF(TSecurityAttributes); 39 | lpSecurityDescriptor:Nil; 40 | Binherithandle:False); 41 | 42 | 43 | PipeBufSize = 1024; 44 | 45 | 46 | Function CreatePipeHandles (Var Inhandle,OutHandle : THandle; APipeBufferSize : Cardinal = PipeBufSize) : Boolean; 47 | begin 48 | // L505 49 | // Result := CreatePipe(@Inhandle,@OutHandle,@piNonInheritablePipe,APipeBufferSize); 50 | Result := CreatePipe(Inhandle,OutHandle,@piNonInheritablePipe,APipeBufferSize); 51 | //writeln('DEBUG: createpipe result: ', result); 52 | end; 53 | 54 | Function TInputPipeStream.GetNumBytesAvailable: DWord; 55 | begin 56 | if not PeekNamedPipe(Handle, nil, 0, nil, @Result, nil) then 57 | Result := 0; 58 | end; 59 | 60 | function TInputPipeStream.GetPosition: Int64; 61 | begin 62 | Result:=FPos; 63 | end; 64 | 65 | procedure TInputPipeStream.InvalidSeek; 66 | begin 67 | Raise EPipeSeek.Create(ENoSeekMsg); 68 | end; 69 | 70 | procedure PipeClose(const FHandle: THandle); inline; 71 | begin 72 | FileClose(FHandle); 73 | end; 74 | -------------------------------------------------------------------------------- /process_win.inc: -------------------------------------------------------------------------------- 1 | { Freepascal TProcess ported to Delphi 2 | 3 | License: FPC Modified LGPL (can use in commercial apps) 4 | 5 | Changes to the code marked with "L505" in comments } 6 | 7 | { 8 | This file is part of the Free Component Library (FCL) 9 | Copyright (c) 1999-2008 by the Free Pascal development team 10 | 11 | See the file COPYING.FPC, included in this distribution, 12 | for details about the copyright. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 | 18 | **********************************************************************} 19 | 20 | Uses 21 | Windows; 22 | 23 | 24 | Resourcestring 25 | SNoCommandLine = 'Cannot execute empty command-line'; 26 | SErrCannotExecute = 'Failed to execute %s : %d'; 27 | { SErrNoSuchProgram = 'Executable not found: "%s"'; 28 | SErrNoTerminalProgram = 'Could not detect X-Terminal program'; 29 | } 30 | 31 | Const 32 | PriorityConstants : Array [TProcessPriority] of Cardinal = 33 | (HIGH_PRIORITY_CLASS,IDLE_PRIORITY_CLASS, 34 | NORMAL_PRIORITY_CLASS,REALTIME_PRIORITY_CLASS); 35 | 36 | procedure TProcess.CloseProcessHandles; 37 | begin 38 | if (FProcessHandle<>0) then 39 | CloseHandle(FProcessHandle); 40 | if (FThreadHandle<>0) then 41 | CloseHandle(FThreadHandle); 42 | end; 43 | 44 | Function TProcess.PeekExitStatus : Boolean; 45 | 46 | begin 47 | GetExitCodeProcess(ProcessHandle,FExitCode); 48 | Result:=(FExitCode<>Still_Active); 49 | end; 50 | 51 | Function GetStartupFlags (P : TProcess): Cardinal; 52 | 53 | begin 54 | With P do 55 | begin 56 | Result:=0; 57 | if poUsePipes in FProcessOptions then 58 | Result:=Result or Startf_UseStdHandles; 59 | if suoUseShowWindow in FStartupOptions then 60 | Result:=Result or startf_USESHOWWINDOW; 61 | if suoUSESIZE in FStartupOptions then 62 | Result:=Result or startf_usesize; 63 | if suoUsePosition in FStartupOptions then 64 | Result:=Result or startf_USEPOSITION; 65 | if suoUSECOUNTCHARS in FStartupoptions then 66 | Result:=Result or startf_usecountchars; 67 | if suoUsefIllAttribute in FStartupOptions then 68 | Result:=Result or startf_USEFILLATTRIBUTE; 69 | end; 70 | end; 71 | 72 | Function GetCreationFlags(P : TProcess) : Cardinal; 73 | 74 | begin 75 | With P do 76 | begin 77 | Result:=0; 78 | if poNoConsole in FProcessOptions then 79 | Result:=Result or Detached_Process; 80 | if poNewConsole in FProcessOptions then 81 | Result:=Result or Create_new_console; 82 | if poNewProcessGroup in FProcessOptions then 83 | Result:=Result or CREATE_NEW_PROCESS_GROUP; 84 | If poRunSuspended in FProcessOptions Then 85 | Result:=Result or Create_Suspended; 86 | if poDebugProcess in FProcessOptions Then 87 | Result:=Result or DEBUG_PROCESS; 88 | if poDebugOnlyThisProcess in FProcessOptions Then 89 | Result:=Result or DEBUG_ONLY_THIS_PROCESS; 90 | if poDefaultErrorMode in FProcessOptions Then 91 | Result:=Result or CREATE_DEFAULT_ERROR_MODE; 92 | result:=result or PriorityConstants[FProcessPriority]; 93 | end; 94 | end; 95 | 96 | //L505 note: unicode string could be used, but msdn says CREATE_UNICODE_ENVIRONMENT 97 | // must be used with CreateProcessW. For now, ansistring will be used instead 98 | Function StringsToPChars(List : TStrings): pointer; 99 | var 100 | EnvBlock, item: ansistring; 101 | I: Integer; 102 | memsize: integer; 103 | begin 104 | EnvBlock := ''; 105 | For I:=0 to List.Count-1 do begin 106 | item := List[i]; 107 | EnvBlock := EnvBlock + item + #0; 108 | end; 109 | EnvBlock := EnvBlock + #0; 110 | memsize := Length(EnvBlock); // if using unicode in the future, remember CHAR size (4) for memory allocation 111 | GetMem(Result, memsize); 112 | CopyMemory(Result, @EnvBlock[1], memsize); 113 | end; 114 | 115 | Procedure InitProcessAttributes(P : TProcess; Var PA : TSecurityAttributes); 116 | 117 | begin 118 | FillChar(PA,SizeOf(PA),0); 119 | PA.nLength := SizeOf(PA); 120 | end; 121 | 122 | Procedure InitThreadAttributes(P : TProcess; Var TA : TSecurityAttributes); 123 | 124 | begin 125 | FillChar(TA,SizeOf(TA),0); 126 | TA.nLength := SizeOf(TA); 127 | end; 128 | 129 | // L505 changed to STARTUPINFOW 130 | // Procedure InitStartupInfo(P : TProcess; Var SI : STARTUPINFOA); 131 | procedure InitStartupInfo(P : TProcess; Var SI : STARTUPINFOW); 132 | Const 133 | SWC : Array [TShowWindowOptions] of Cardinal = 134 | (0,SW_HIDE,SW_Maximize,SW_Minimize,SW_Restore,SW_Show, 135 | SW_ShowDefault,SW_ShowMaximized,SW_ShowMinimized, 136 | SW_showMinNOActive,SW_ShowNA,SW_ShowNoActivate,SW_ShowNormal); 137 | 138 | begin 139 | FillChar(SI,SizeOf(SI),0); 140 | With SI do 141 | begin 142 | dwFlags:=GetStartupFlags(P); 143 | if P.FShowWindow<>swoNone then 144 | dwFlags:=dwFlags or Startf_UseShowWindow 145 | else 146 | dwFlags:=dwFlags and not Startf_UseShowWindow; 147 | wShowWindow:=SWC[P.FShowWindow]; 148 | if (poUsePipes in P.Options) then 149 | begin 150 | dwFlags:=dwFlags or Startf_UseStdHandles; 151 | end; 152 | if P.FillAttribute<>0 then 153 | begin 154 | dwFlags:=dwFlags or Startf_UseFillAttribute; 155 | dwFillAttribute:=P.FillAttribute; 156 | end; 157 | dwXCountChars:=P.WindowColumns; 158 | dwYCountChars:=P.WindowRows; 159 | dwYsize:=P.WindowHeight; 160 | dwXsize:=P.WindowWidth; 161 | dwy:=P.WindowTop; 162 | dwX:=P.WindowLeft; 163 | end; 164 | end; 165 | 166 | { The handles that are to be passed to the child process must be 167 | inheritable. On the other hand, only non-inheritable handles 168 | allow the sending of EOF when the write-end is closed. This 169 | function is used to duplicate the child process's ends of the 170 | handles into inheritable ones, leaving the parent-side handles 171 | non-inheritable. 172 | } 173 | function DuplicateHandleFP(var handle: THandle): Boolean; 174 | var 175 | oldHandle: THandle; 176 | begin 177 | oldHandle := handle; 178 | Result := DuplicateHandle 179 | ( GetCurrentProcess(), 180 | oldHandle, 181 | GetCurrentProcess(), 182 | @handle, 183 | 0, 184 | true, 185 | DUPLICATE_SAME_ACCESS 186 | ); 187 | if Result then 188 | Result := CloseHandle(oldHandle); 189 | end; 190 | 191 | // L505 changed to TStartupInfoW 192 | // Procedure CreatePipes(Var HI,HO,HE : Thandle; Var SI : TStartupInfoA; CE : Boolean; APipeBufferSize : Cardinal); 193 | procedure CreatePipes(Var HI,HO,HE : Thandle; Var SI : TStartupInfoW; CE : Boolean; APipeBufferSize : Cardinal); 194 | begin 195 | CreatePipeHandles(SI.hStdInput,HI, APipeBufferSize); 196 | DuplicateHandleFP(SI.hStdInput); 197 | CreatePipeHandles(HO,Si.hStdOutput, APipeBufferSize); 198 | DuplicateHandleFP(Si.hStdOutput); 199 | if CE then begin 200 | CreatePipeHandles(HE,SI.hStdError, APipeBufferSize); 201 | DuplicateHandleFP( SI.hStdError); 202 | end 203 | else 204 | begin 205 | SI.hStdError:=SI.hStdOutput; 206 | HE:=HO; 207 | end; 208 | end; 209 | 210 | Function MaybeQuote(Const S : String) : String; 211 | begin 212 | If (Pos(' ',S)<>0) then 213 | Result:='"'+S+'"' 214 | else 215 | Result:=S; 216 | end; 217 | 218 | Function MaybeQuoteIfNotQuoted(Const S : String) : String; 219 | begin 220 | If (Pos(' ',S)<>0) and (pos('"',S)=0) then 221 | Result:='"'+S+'"' 222 | else 223 | Result:=S; 224 | end; 225 | 226 | Procedure TProcess.Execute; 227 | Var 228 | i : Integer; 229 | PName,PDir,PCommandLine : PChar; 230 | FEnv: pointer; 231 | FCreationFlags : Cardinal; 232 | FProcessAttributes : TSecurityAttributes; 233 | FThreadAttributes : TSecurityAttributes; 234 | FProcessInformation : TProcessInformation; 235 | // FStartupInfo : STARTUPINFOA; // L505 236 | FStartupInfo : STARTUPINFOW; // L505 237 | HI,HO,HE : THandle; 238 | Cmd : String; 239 | 240 | begin 241 | PName:=Nil; 242 | PCommandLine:=Nil; 243 | PDir:=Nil; 244 | 245 | if (FApplicationName='') and (FCommandLine='') and (FExecutable='') then 246 | Raise EProcess.Create(SNoCommandline); 247 | if (FApplicationName<>'') then 248 | begin 249 | PName:=PChar(FApplicationName); 250 | PCommandLine:=PChar(FCommandLine); 251 | end 252 | else If (FCommandLine<>'') then 253 | PCommandLine:=PChar(FCommandLine) 254 | else if (Fexecutable<>'') then 255 | begin 256 | Cmd:=MaybeQuoteIfNotQuoted(Executable); 257 | For I:=0 to Parameters.Count-1 do 258 | Cmd:=Cmd+' '+MaybeQuoteIfNotQuoted(Parameters[i]); 259 | PCommandLine:=PChar(Cmd); 260 | end; 261 | If FCurrentDirectory<>'' then 262 | PDir:=PChar(FCurrentDirectory); 263 | if FEnvironment.Count<>0 then 264 | FEnv:=StringsToPChars(FEnvironment) 265 | else begin 266 | // writeln('DEBUG: environment nil'); 267 | FEnv:=Nil; 268 | end; 269 | 270 | Try 271 | FCreationFlags:=GetCreationFlags(Self); 272 | InitProcessAttributes(Self,FProcessAttributes); 273 | InitThreadAttributes(Self,FThreadAttributes); 274 | InitStartupInfo(Self,FStartUpInfo); 275 | If poUsePipes in FProcessOptions then begin 276 | CreatePipes(HI,HO,HE,FStartupInfo,Not(poStdErrToOutPut in FProcessOptions), FPipeBufferSize); 277 | end; 278 | 279 | Try 280 | // L505: changed to CreateProcessW, fpc uses CreateProcess which is CreateProcessA 281 | If Not CreateProcessW(PName,PCommandLine,@FProcessAttributes,@FThreadAttributes, 282 | FInheritHandles,FCreationFlags,FEnv,PDir,FStartupInfo, 283 | fProcessInformation) then 284 | Raise EProcess.CreateFmt(SErrCannotExecute,[FCommandLine,GetLastError]); 285 | FProcessHandle:=FProcessInformation.hProcess; 286 | FThreadHandle:=FProcessInformation.hThread; 287 | FProcessID:=FProcessINformation.dwProcessID; 288 | Finally 289 | if POUsePipes in FProcessOptions then 290 | begin 291 | FileClose(FStartupInfo.hStdInput); 292 | FileClose(FStartupInfo.hStdOutput); 293 | if Not (poStdErrToOutPut in FProcessOptions) then 294 | FileClose(FStartupInfo.hStdError); 295 | CreateStreams(HI,HO,HE); 296 | end; 297 | end; 298 | FRunning:=True; 299 | Finally 300 | If FEnv<>Nil then 301 | FreeMem(FEnv); 302 | end; 303 | if not (csDesigning in ComponentState) and // This would hang the IDE ! 304 | (poWaitOnExit in FProcessOptions) and 305 | not (poRunSuspended in FProcessOptions) then 306 | WaitOnExit; 307 | end; 308 | 309 | Function TProcess.WaitOnExit : Boolean; 310 | Var 311 | R : DWord; 312 | begin 313 | R:=WaitForSingleObject (FProcessHandle,Infinite); 314 | Result:=(R<>Wait_Failed); 315 | If Result then 316 | GetExitStatus; 317 | FRunning:=False; 318 | end; 319 | 320 | Function TProcess.Suspend : Longint; 321 | begin 322 | Result:=SuspendThread(ThreadHandle); 323 | end; 324 | 325 | Function TProcess.Resume : LongInt; 326 | begin 327 | Result:=ResumeThread(ThreadHandle); 328 | end; 329 | 330 | Function TProcess.Terminate(AExitCode : Integer) : Boolean; 331 | begin 332 | Result:=False; 333 | If ExitStatus=Still_active then 334 | Result:=TerminateProcess(Handle,AexitCode); 335 | end; 336 | 337 | Procedure TProcess.SetShowWindow (Value : TShowWindowOptions); 338 | begin 339 | FShowWindow:=Value; 340 | end; 341 | --------------------------------------------------------------------------------