简体   繁体   English

Turbo C和批处理文件

[英]turbo c & batch file

My batch file is executing with c program but when I used start notepad.exe in batch file 我的批处理文件正在用C程序执行,但是当我在批处理文件中使用启动notepad.exe时

it shows bad command .But when I execute my batch file individully it works perfect.What's 它显示了错误的命令。但是当我单独执行批处理文件时,它可以完美运行。

the reason? 原因?

Could you please post your bat file? 你能张贴你的蝙蝠文件吗? It could be that the path to notepad.exe is relative to where you are running your bat file when you execute it manually, but when you call it from your C application you are running it from the C executable's location so it no longer finds either notepad.exe or a fiel that you may be passing to notepad.exe 可能是notepad.exe的路径与手动执行bat文件时的运行位置有关,但是当您从C应用程序调用它时,您是从C可执行文件的位置运行它的,因此它不再找到notepad.exe或您可能要传递给notepad.exe的文件

它必须与notepad.exe的路径有关,如果您在Windows上,则尝试将notepad.exe的路径添加到环境变量“ PATH”中,这可能会简化很多事情。

you say that you execute the batch file from the C program. 您说您是从C程序执行批处理文件。 are you sure the environment is properly setup when you start executing the batch file ? 开始执行批处理文件时,确定环境设置正确吗?

if the PATH environment variable is not correctly set when executing the batch file, then the batch file will not execute. 如果在执行批处理文件时未正确设置PATH环境变量,则该批处理文件将不会执行。 but the batch file will work without problem when launched from the command line, because the environment is correctly set in this case. 但是从命令行启动该批处理文件将可以正常工作,因为在这种情况下,环境已正确设置。

start is an internal command of cmd.exe ; startcmd.exe的内部命令; it is not a program by itself. 它本身不是程序。 To run start you need to run cmd.exe and have that cmd.exe do the start thing. 要运行start您需要运行cmd.exe并让该cmd.exestart

The system() C function executes a shell (likely cmd.exe in Windows) and passes the argument to that shell -- and start "works". system() C函数执行一个外壳程序(在Windows中可能是cmd.exe )并将参数传递给该外壳程序-并start “工作”。

The exec* functions do not load a shell -- and start by itself "don't work": it needs to be 'inside' cmd.exe exec*函数不会加载外壳程序,而是单独start “不起作用”:它必须在cmd.exe内部

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void) {
  // system "works"
  system("start C:\\tmp");

  // this don't work
  execl("start", "start", "C:\\Windows", (char*)0);
  printf("Oops: execl with start failed\n");

  // this "works"
  execl("C:\\Windows\\System32\\cmd.exe", "start", "/c", "start", "C:\\Windows\\", (char*)0);
  printf("Oops: execl with <path>\\cmd.exe failed\n");

  return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM