Turbo C ++系统功能运行可执行文件 [英] Turbo C++ system function running an executable

查看:107
本文介绍了Turbo C ++系统功能运行可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从turbo c ++运行任何exe文件?我知道我应该停止使用turbo c ++,而将其移到Dev或Code :: Blocks,但是我的学校不同意,所以我必须使用它。

How to run any exe file from turbo c++? I know that I should stop using turbo c++ and move one to Dev or Code::Blocks, but my school doesn't agree so I gotta wing it.

我只是想知道如何在有或没有system()函数的情况下运行文件。
欢迎任何建议

I just want to know how to run a file with or without the system() function. Any kind of advice is welcome

这是我到目前为止尝试过的:

Here's what I have tried so far:

1

#include<process.h>
int main()
{
    system("tnfsv13.exe");     //tnfsv being a 16-bit application(The need for slowness v 13)
    return 0;
} 

2

  #include<process.h>
    int main()
    {
        system("tnfsv13.bat");     
         return 0;
    } 




  1. tnfsv13 .bat:

  1. tnfsv13.bat:

开始 c:\TurboC3\BIN\ tnfsv13.exe

start "c:\TurboC3\BIN\" tnfsv13.exe

注:只是一个疑问,你们:system()在Windows XP中不起作用。我在Windows 7中使用dosbox进行了尝试,效果很好,但在XP中却完全不起作用。甚至system( dir)命令似乎都不起作用,但是system(NULL)返回1。任何猜测为什么?

NOTE: Just a doubt, you guys: system() is not working in windows XP. I tried it using dosbox in windows 7 and it works well, but in XP it does absolutely nothing. Not even the system("dir") command seems to work but system(NULL) returns 1. Any guesses why?

谢谢。

推荐答案

您还可以使用Turbo C ++的 execl()函数。 execl()加载并运行 C:\\TC\\BIN\\tnfsv13.exe NULL 表示没有参数要发送到 tnfsv13.exe 。如果发生错误, execl()返回-1到 int c 中。

You can also use Turbo C++'s execl() function. execl() loads and runs C:\\TC\\BIN\\tnfsv13.exe. NULL means there are no arguments to send to tnfsv13.exe. If an error occurs, execl() returns -1 into int c .

#include<stdio.h>
#include<process.h>

int main()
{
    int c = execl("C:\\TC\\BIN\\tnfsv13.exe", NULL);


    return 0;
}

说明:

execl() loads and executes a new child process.  Because the child
process is placed in the memory currently occupied by the calling
process, there must be sufficient memory to load and execute it.

'pathname' specifies the file name of the child process.  If
'pathname' has a file name extension, then only that file is searched
for. If 'pathname' ends with a period (.), then 'pathname' without an
extension is searched for.  If that filename is not found, then
".EXE" is appended and execl() searches again.  If 'pathname' has no
extension and does not end with a period, then execl() searches for
'pathname' and, if it is not found, appends ".COM" and searches
again.  If that is not found, it appends ".EXE" and searches again.

 'arg0', 'arg1',...'argn' are passed to the child process as command-
line parameters.  A NULL pointer must follow 'argn' to terminate the
list of arguments. 'arg0' must not be NULL, and is usually set to
'pathname'.

The combined length of all the strings forming the argument list
passed to the child process must not exceed 128 bytes.  This includes
"n" (for 0-n arguments) space characters (required to separate the
arguments) but does not include the null ('\0') terminating
character.

   Returns:     If execl() is successful, it does not return to the
                calling process. (See the spawn...() routines for a
                similar function that can return to the calling
                process). If an error occurs, execl() returns -1 to
                the calling process. On error, 'errno' (defined in
                <errno.h>) is set to one of the following values
                (defined in <errno.h>):

                E2BIG       Argument list or environment list too big.
                              (List > 128 bytes, or environment > 32k)
                EACCES      Locking or sharing violation on file.
                              (MS-DOS 3.0 and later)
                EMFILE      Too many files open.
                ENOENT      File or path not found.
                ENOEXEC     File not executable.
                ENOMEM      Not enough memory.

     Notes:     Any file open when an exec call is made remains open
                in the child process.  This includes
                'stdin','stdout', 'stderr', 'stdaux', and 'stdprn'.

                The child process acquires the environment of the
                calling process.

                execl() does not preserve the translation modes of
                open files.  Use setmode() in the child process to
                set the desired translation modes.

                See the spawn...() routines for similar though more
                flexible functions that can return to the calling
                program.

   Caution:     The file pointers to open buffered files are not
                always preserved correctly.  The information in the
                buffer may be lost.

                Signal settings are not preserved.  They are reset to
                the default in the child process.

--------------------- -----------示例---------------------------------

-------------------------------- Example ---------------------------------

The following statements transfer execution to the child process
"child.exe" and pass it the three arguments "child", "arg1",
and"arg2":

       #include <process.h>    /* for 'execl' */
       #include <stdio.h>      /* for 'printf' and 'NULL' */
       #include <errno.h>      /* for 'errno', 'ENOENT' and 'ENOMEM' */

       main()
       {
           execl("child.exe", "child", "arg1", "arg2", NULL);
           /* only get here on an exec error */
           if (errno == ENOENT)
               printf("child.exe not found in current directory\n");
           else if (errno == ENOMEM)
               printf("not enough memory to execute child.exe\n");
           else
               printf("  error #%d trying to exec child.exe\n", errno);
       }

这篇关于Turbo C ++系统功能运行可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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