system函数执行的有空格的路径问题

猿小二 2011-04-19 02:54:42
YinDaoPath是一个路径,路径中有空格
YinDaoPath = "c:\Documents and Settings\IA\Desktop\TestCompare\TestCompare\yindao.bat"
system(YinDaoPath);

YinDaoPath是通过拼接形成的,CString 类型
所以要保留~~~

请帮忙解决一下

最好能具体一点 有代码更好
...全文
815 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
alweeq86 2011-04-19
  • 打赏
  • 举报
回复
那就在前面后后面插入引号

[Quote=引用 11 楼 quwei3930921 的回复:]
引用 9 楼 alweeq86 的回复:
C/C++ code

CString YinDaoPath = "c:\\Documents and Settings\\IA\\Desktop\\TestCompare\\TestCompare\\yindao.bat"

system(YinDaoPath.GetBuff());

路径是还是因为有空格,system()不执行.bat文……
[/Quote]
赵4老师 2011-04-19
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 quwei3930921 的回复:]
问题是我现在已经把路径存进以变量里面了,没办法使用引号引起来啊~~
[/Quote]
#include <process.h>
#include <stdio.h>
char YinDaoPath[] = "c:\\Documents and Settings\\IA\\Desktop\\TestCompare\\TestCompare\\yindao.bat";
char cmdstr[300];
void main () {
sprintf(cmdstr,"\"%s\"",YinDaoPath);//或者sprintf(cmdstr,"cmd /c \"%s\"",YinDaoPath);
system(cmdstr);
}
赵4老师 2011-04-19
  • 打赏
  • 举报
回复
#include <process.h>
char YinDaoPath[] = "cmd /c \"c:\\Documents and Settings\\IA\\Desktop\\TestCompare\\TestCompare\\yindao.bat\"";
void main () {
system(YinDaoPath);
}
hzy694358 2011-04-19
  • 打赏
  • 举报
回复
just like this:

YinDaoPath = _T("\"") + m_CurrentPath + _T("\\yindao.bat\"");
猿小二 2011-04-19
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 alweeq86 的回复:]
C/C++ code

CString YinDaoPath = "c:\\Documents and Settings\\IA\\Desktop\\TestCompare\\TestCompare\\yindao.bat"

system(YinDaoPath.GetBuff());
[/Quote]
路径是还是因为有空格,system()不执行.bat文件
猿小二 2011-04-19
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 alweeq86 的回复:]
C/C++ code

string s="pause";
cout<<" dddddd ";
system(s.c_str());
[/Quote]
什么意思? 不明白啊~能说清楚点吗
alweeq86 2011-04-19
  • 打赏
  • 举报
回复

CString YinDaoPath = "c:\\Documents and Settings\\IA\\Desktop\\TestCompare\\TestCompare\\yindao.bat"

system(YinDaoPath.GetBuff());
alweeq86 2011-04-19
  • 打赏
  • 举报
回复

string s="pause";
cout<<" dddddd ";
system(s.c_str());
猿小二 2011-04-19
  • 打赏
  • 举报
回复
补充下:YinDaoPath是通过
char acCurrentPath[100];
GetCurrentDirectory(100, acCurrentPath);
m_CurrentPath = (CString)acCurrentPath;

YinDaoPath = m_CurrentPath + _T("\\yindao.bat");
获得的 ,
现在想执行这个.bat文件
猿小二 2011-04-19
  • 打赏
  • 举报
回复
问题是我现在已经把路径存进以变量里面了,没办法使用引号引起来啊~~
c_losed 2011-04-19
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhao4zhong1 的回复:]

纠正上帖:
YinDaoPath = "\"c:\\Documents and Settings\\IA\Desktop\\TestCompare\\TestCompare\\yindao.bat\""
[/Quote]
赵老师V5
膜拜、、、
机智的呆呆 2011-04-19
  • 打赏
  • 举报
回复
路径用双引号引起来
赵4老师 2011-04-19
  • 打赏
  • 举报
回复
纠正上帖:
YinDaoPath = "\"c:\\Documents and Settings\\IA\Desktop\\TestCompare\\TestCompare\\yindao.bat\""
赵4老师 2011-04-19
  • 打赏
  • 举报
回复
YinDaoPath = "\"c:\Documents and Settings\IA\Desktop\TestCompare\TestCompare\yindao.bat\""
system(YinDaoPath);


c_losed 2011-04-19
  • 打赏
  • 举报
回复

#include <iostream>
#include <atlstr.h>
using namespace std;

void main()
{
CString YinDaoPath = "c:\\Documents and Settings\\IA\\Desktop\\TestCompare\\TestCompare\\yindao.bat";

if (CopyFile(YinDaoPath, "D:\\yindao.bat", FALSE))
{
system("D:\\yindao.bat");
}
else
{
printf("文件拷贝失败");
}


}

前提是有D盘

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧