使用环境变量作为参数创建进程 [英] Create Process with Environment variable as a argument

查看:100
本文介绍了使用环境变量作为参数创建进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在C:\Ming32\文件夹中安装了Mingw32 .

我将此路径添加到了PATH variables.

当我从任何路径在命令提示符下键入命令mingw32-make.exe时,系统都能够找到该文件.但是,当我尝试使用CreateProcess 作为第一个参数时,它失败并显示错误代码2.

另外,我尝试作为第二个参数,并且得到错误代码237.

如何解决这个问题呢.我不想在代码中使用Mingw32 路径,因为我的应用程序将在不同的系统上运行,并且它们可能会将gcc 安装在不同的文件夹中.

谢谢,

Hi,

I installed Mingw32 in C:\Ming32\ Folder.

I added this path to PATH variable.

When I type the command mingw32-make.exe in Command prompt from any path, the system is able to find the file. But when I tried with the CreateProcess as a first argument it is failing with error code 2.

Also i tried as a second argument and i got the error code 237.

How to solve this problem. I don''t want to use the Mingw32 path in my code, because my application will run in different systems and they may install the gcc in different folders.

Thanks,

推荐答案

好吧,您可以选择在安装时确定mingw32的安装路径,或者更好地为它提供可配置的额外机会.你的申请.在大多数情况下,除了算法或与系统相关的常量之外,我实际上都尽量避免使用硬编码的内容.

除此之外,您可能在 MSDN文档中CreateProcess [ ^ ]:

Well on option you''ll have is to either determine the mingw32 installation path at install time or better yet supply the additional opportunity to have this configurable in your application. For the most part I really try to avoid hard coded stuff except for algorithm or system relevant constants.

Besides that you probably missed this bit here in the MSDN documentation on CreateProcess[^]:

字符串可以指定要执行的模块的完整路径和文件名,也可以指定部分名称.对于部分名称,该函数使用当前驱动器和当前目录来完成规范. 该功能将不使用搜索路径.此参数必须包含文件扩展名;没有默认扩展名.
The string can specify the full path and file name of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification. The function will not use the search path. This parameter must include the file name extension; no default extension is assumed.


-MSDN
您所追求的功能通常由/a外壳提供(例如cmd).您可能想看一下功能 ShellExecute [ ^ ].

问候,

Manfred


—MSDN
The functionality you are after is usually supplied by the/a shell (cmd e.g.). You might want to look at the function ShellExecute[^].

Regards,

Manfred


将环境变量作为参数传递毫无意义.参数的语义完全由用于作为子进程运行的应用程序定义.该应用程序接收到命令行字符串(通常在应用程序文件名后在控制台中键入),并根据其语义由应用程序处理.

从推测的角度来说,即使应用程序的某些命令行参数的语义可能意味着环境变量的名称和/或值,但没有合理的应用程序会使用这种语义,因为这根本没有任何意义. >
环境变量充当系统全局的全局常量"或全局只读值".它们用于某些全局设置,并且在任何应用程序的运行期间都不会更改,除非少数情况下需要更改某些全局设置或添加某些设置.有时是由于安装了新的软件产品而导致的.

而且,使用环境变量来安装(和稍后运行)任何应用程序都表明配置风格确实很差,或者可能是与某些旧版软件向后兼容的方式.更合适的样式是针对每个应用程序使用系统隔离的配置或设置文件.

有关更多详细信息,请参见 http://en.wikipedia.org/wiki/Environment_variable [
Passing an environment variable as a parameter makes no sense, whatsoever. The semantic of parameters is totally defined by the application used to run as a child process. This application received a command line string (which more usually typed in the console after the name of the application file) and processed by the application, according to its semantic.

Even though, speculatively speaking, the semantics of some command line parameters of the application might mean the name and/or value of an environment variable, no reasonable application will use such semantic, because it would not make any sense at all.

The environment variables play the role of "global constants" or rather "global read-only values", global to the system. They are used for some global settings and never changed during run-time of any application, excluding rare cases when one needs to change some global settings or add some settings. Sometimes it happens as a result of installation of a new software product.

Moreover, using environment variables for installation (and later run time) of any application is the indication of a really bad style of configuration, or maybe the way of backward compatibility with some software legacy. More appropriate style is using system isolated configuration or settings files, per application.

For more detail, please see http://en.wikipedia.org/wiki/Environment_variable[^].



The error message is explained in my comment to the comment by JackDingler to the original question, please see.

—SA


这篇关于使用环境变量作为参数创建进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆