运行代码的名称 [英] name of running code

查看:67
本文介绍了运行代码的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取正在运行的代码的名称,以便将其包含在

带时间戳的日志文件中。

..

我记得,有一种ANSI标准的方式可以向正在运行的程序询问

的名称。但是我忘记了它的具体细节。

..

你是怎么做到的?

..

lbrtchx

解决方案

Albretch Mueller写道:

我需要得到代号的名称运行以便将其包含在带有时间戳的日志文件中。

我记得,有一种ANSI标准方法可以向正在运行的程序询问其名称。但是我忘记了它的具体细节。

你是怎么做到的?



argv [0]?


-

Ian Collins。


2006-06-05,Ian Collins< ia * *****@hotmail.com>写道:

Albretch Mueller写道:

我需要获取正在运行的代码的名称,以便将其包含在带有时间戳的日志文件中。

我记得,有一种ANSI标准方法可以向正在运行的程序询问其名称。但我忘记了它的具体细节。

你是怎么做到的?


argv [0]?



/ *你必须用这种方式定义main():* /

int main(int argc,char * argv [])

{

/ *此处代码* /

返回0;

}


argc包含参数个数加一个,而argv []

是它们的数组。如Ian所述,argv [0]几乎总是程序

名称。


-

Andrew Poelstra< http://www.wpsoftware.net/blog >

给我发电子邮件,请使用apoelstra。在上面的地址。

如果我们只是让偷猎者进入动物园,我们会给b
$ b更少的人和更多花式钢琴!


在帖子中你可以告诉我这个问题的解释吗 Eric

Sosman

指出,argv [0]将不会保证标准不保证

不是

NULL指针,此外可执行文件的名称可能不是唯一定义的
。因此,甚至不清楚标准函数

是什么?b $ b应该提供运行代码的名称。


那么有没有办法引用新闻组中的特定帖子

反对

到thead title?


I need to get the name of the very code running in order to include it in a
time stamped log file.
..
As I remember, there is an ANSI standard way to ask a running program for
its name. But I forgot the specifics of it.
..
How is it that you do that?
..
lbrtchx

解决方案

Albretch Mueller wrote:

I need to get the name of the very code running in order to include it in a
time stamped log file.
.
As I remember, there is an ANSI standard way to ask a running program for
its name. But I forgot the specifics of it.
.
How is it that you do that?
.


argv[0] ?

--
Ian Collins.


On 2006-06-05, Ian Collins <ia******@hotmail.com> wrote:

Albretch Mueller wrote:

I need to get the name of the very code running in order to include it in a
time stamped log file.
.
As I remember, there is an ANSI standard way to ask a running program for
its name. But I forgot the specifics of it.
.
How is it that you do that?
.


argv[0] ?



/* You must define main() this way: */
int main (int argc, char *argv[])
{
/* Code here */
return 0;
}

argc contains the number of arguments plus one, and argv[]
is the array of them. argv[0] is almost always the program
name, as Ian stated.

--
Andrew Poelstra < http://www.wpsoftware.net/blog >
To email me, use "apoelstra" at the above address.
If we would just let the poachers into the zoo, we''d
have less squashed people and more fancy pianos!


In the thread "Can u tell me the explanation reg this problem" Eric
Sosman
points out that it is not guaranteed by the standard that argv[0] will
not be a
NULL pointer and furthermore that the name of an executable may not be
uniquely defined. So it is not even clear what a standard function
would be
supposed to provide as "name of running code".

By the way is there a way to refer to a specific post in a newsgroup as
opposed
to thead title ?


这篇关于运行代码的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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