EnglishРусский  

   ..

   arr.g

   arrstr.g

   arrustr.g

   buf.g

   changes.txt

   console.g

   fcopy.g

   ffind.g

   file.g

   hash.g

   math.g

   process.g

   search.g

   stack.g

   stdlib.g

   str.g

   stradv.g

   strfile.g

   system.g

   ustr.g

Ads

Perfect Automation tool
All-In-One: Script editor, Launcher, Scheduler, Keyboard & Mouse Recorder. Try now!

CreateInstall
Freeware and commercial installers.

Cell Phone Batteries
Batteries Plus offers batteries for laptop, camcorder, cell phone, camera.

Gentee needs your help!
How to advertise with us
 
laptop battery

source\lib\stdlib\process.g
  1 /******************************************************************************
  2 *
  3 * Copyright (C) 2004-2007, The Gentee Group. All rights reserved. 
  4 * This file is part of the Gentee open source project - http://www.gentee.com. 
  5 * 
  6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT"). 
  7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS 
  8 * ACCEPTANCE OF THE AGREEMENT.
  9 *
 10 * Author: Alexey Krivonogov ( gentee )
 11 *
 12 ******************************************************************************/
 13 
 14 /*-----------------------------------------------------------------------------
 15 * Id: process L "Process"
 16 * 
 17 * Summary: Process, shell, arguments and environment functions.
 18 *
 19 * List: *,argc,argv,exit,getenv,processf,setenv,shell  
 20 * 
 21 -----------------------------------------------------------------------------*/
 22 
 23 /*-----------------------------------------------------------------------------
 24 * Id: processf F process
 25 *
 26 * Summary: Starting a process.  
 27 *  
 28 * Params: cmdline - The command line. 
 29           workdir - The working directory. It can be 0->str. 
 30           result - The pointer to uint for getting the result. If #b(0), the /
 31           function will not wait until the process finishes its work. 
 32 * 
 33 * Return: #b(1) if the calling process was successful; otherwise #b(0). 
 34 *
 35 -----------------------------------------------------------------------------*/
 36 
 37 func uint process( str cmdline, str workdir, uint result )
 38 {
 39    PROCESS_INFORMATION  stpi
 40    STARTUPINFO          start
 41 
 42    start.cb = sizeof( STARTUPINFO )
 43 
 44    if  CreateProcess( 0, cmdline.ptr( ), 0, 0, 1,
 45                      $CREATE_DEFAULT_ERROR_MODE | $NORMAL_PRIORITY_CLASS, 
 46                      0, ?( workdir && *workdir, workdir.ptr(), 0 ), 
 47                      start, stpi )
 48    {
 49       if result 
 50       {
 51          WaitForSingleObject( stpi.hThread, $INFINITE )
 52          GetExitCodeProcess( stpi.hProcess, result )
 53       }
 54       CloseHandle( stpi.hThread )
 55       CloseHandle( stpi.hProcess )
 56       return 1
 57    }
 58    return 0
 59 }
 60 
 61 /*-----------------------------------------------------------------------------
 62 * Id: shell F
 63 *
 64 * Summary: Launch or open a file in the associated application.  
 65 *  
 66 * Params: name - Filename. 
 67 * 
 68 -----------------------------------------------------------------------------*/
 69 
 70 func shell( str name )
 71 {
 72    ShellExecute( 0, "open".ptr(), name.ptr(), 0, 0, $SW_SHOWNORMAL )
 73 }
 74 
 75 /*-----------------------------------------------------------------------------
 76 * Id: exit F
 77 *
 78 * Summary: Exit the current program.  
 79 *  
 80 * Params: code - A return code or the results of the work of the program. 
 81 * 
 82 -----------------------------------------------------------------------------*/
 83 
 84 func exit( uint code )
 85 {
 86    ExitProcess( code )
 87 }
 88 
 89 /*-----------------------------------------------------------------------------
 90 * Id: getenv F 
 91 *
 92 * Summary: Get an environment variable.
 93 *  
 94 * Params: varname - Environment variable name. 
 95           ret - String for getting the value. 
 96 * 
 97 * Return: #lng/retpar( ret ) 
 98 *
 99 -----------------------------------------------------------------------------*/
100 
101 func str getenv( str varname, str ret )
102 {
103    uint ptr
104    
105    ret.clear()
106    if ptr = _getenv( varname.ptr())
107    {
108       ret.copy( ptr )
109    }
110    return ret   
111 }
112 
113 /*-----------------------------------------------------------------------------
114 ** Id: setenv F 
115 *
116 * Summary: Set a value of an environment variable. The function adds new
117            environment variable or modifies the value of the existing
118            environment variable. New values will be valid only in the 
119            current process. 
120 *  
121 * Params: varname - Environment variable name. 
122           varvalue - A new value of the environment variable. 
123 * 
124 * Return: #lng/retf# 
125 *
126 -----------------------------------------------------------------------------*/
127 
128 func uint setenv( str varname, str varvalue )
129 {
130    return ?( _setenv( "\(varname)=\(varvalue)".ptr()), 0, 1 )   
131 }
132 
Edit