system函数求助一下

hearoequal 2009-02-06 01:27:22
不知道在哪里发帖合适
就在c++区问下

我在c++里面写
了个
system("ipconfig -all > %s", strPath )

当strPath中出现的路径不是DOS能接受的文件夹的名字的时候
我导出的文件会失败

请问有没有办法解决??
还是无解??
...全文
1806 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
Wolf0403 2009-02-06
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 fetag 的回复:]
这是我的一个程序中的调用system()函数的实际代码,希望对你有帮助:

system(" \"D:\\Program Files\\Wireshark\\wireshark.exe\" C:\\test.cap ");
[/Quote]

wireshark.. 看到倒胃。。
yuzl32 2009-02-06
  • 打赏
  • 举报
回复
这样敲:ipconfig -all > C:\\Program Files\\temp\\temp.txt
'\' -> '\\'
hearoequal 2009-02-06
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 fanlehai 的回复:]
lg
[/Quote]

不要随便叫人老公
影响不好
Learn-anything 2009-02-06
  • 打赏
  • 举报
回复
lg
hearoequal 2009-02-06
  • 打赏
  • 举报
回复
你们都是星星

我怕给得少

我明天加了分来结贴
hearoequal 2009-02-06
  • 打赏
  • 举报
回复
谢谢大家回帖

我看到好多星星…………

大致确定了不是system函数 我调用上的问题

是>符号导出文件的时候不接受大于8个字符的文件夹

9楼给我提了个醒

我想了个解决办法
呵呵


strTemp.Format( "ipconfig -all > ./temp.txt" );
SetCurrentDirectory( strPath );
system( strTemp );

ltc_mouse 2009-02-06
  • 打赏
  • 举报
回复
fetag在11楼的参考代码中用了引号把路径名引起来,应该是可行的,lz可以试试

即:
CString strTemp;
strTemp.Format("ipconfig -all > \"%s\"", strPath);
system(strTemp);
hearoequal 2009-02-06
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 ltc_mouse 的回复:]
先用system()把文件保存到一个固定的文件如temp.txt
再使用MoveFile/MoveFileEx修改文件名?
[/Quote]

你的方法应该可行
先保存到一个DOS能够接受的路径
在用WINDOWS函数转移


[Quote=引用 10 楼 fetag 的回复:]
自己处理下输入路径,在程序内部处理,变成这样的:
C:\\Program Files\\temp\\temp.txt
[/Quote]

已经确认不是少打\的问题
如果是C:\temp\temp.txt就是好的
是文件夹的名字DOS不能接受
独孤过儿 2009-02-06
  • 打赏
  • 举报
回复
这是我的一个程序中的调用system()函数的实际代码,希望对你有帮助:

system(" \"D:\\Program Files\\Wireshark\\wireshark.exe\" C:\\test.cap ");
独孤过儿 2009-02-06
  • 打赏
  • 举报
回复
自己处理下输入路径,在程序内部处理,变成这样的:
C:\\Program Files\\temp\\temp.txt
ltc_mouse 2009-02-06
  • 打赏
  • 举报
回复
先用system()把文件保存到一个固定的文件如temp.txt
再使用MoveFile/MoveFileEx修改文件名?
hearoequal 2009-02-06
  • 打赏
  • 举报
回复
楼上的你贴MSDN的东西
还不是不知道怎么写
我的意思是

ipconfig -all > C:\Program Files\temp\temp.txt
这个写成ShellExecute 咋写
调用的哪个exe我都不知道




而且我已经查到问题所在了
不光是system调用

我就是在命令行里面敲ipconfig -all > C:\Program Files\temp\temp.txt
都不能导出文件
看来>操作符 必须是DOS下路径才行

看来要另外想办法
waizqfor 2009-02-06
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 hearoequal 的回复:]
ShellExecute的话
我这个命令该怎么写??


ShellExecute(handle, "open", 这里3个参数咋写, SW_SHOWNORMAL);
[/Quote]

lpFile
[in] A pointer to a null-terminated string that specifies the file or object on which to execute the specified verb. To specify a Shell namespace object, pass the fully qualified parse name. Note that not all verbs are supported on all objects. For example, not all document types support the "print" verb. If a relative path is used for the lpDirectory parameter do not use a relative path for lpFile.
lpParameters
[in] If lpFile specifies an executable file, this parameter is a pointer to a null-terminated string that specifies the parameters to be passed to the application. The format of this string is determined by the verb that is to be invoked. If lpFile specifies a document file, lpParameters should be NULL.
lpDirectory
[in] A pointer to a null-terminated string that specifies the default (working) directory for the action. If this value is NULL, the current working directory is used. If a relative path is provided at lpFile, do not use a relative path for lpDirectory.
hearoequal 2009-02-06
  • 打赏
  • 举报
回复
ShellExecute的话
我这个命令该怎么写??


ShellExecute(handle, "open", 这里3个参数咋写, SW_SHOWNORMAL);
梅文海 2009-02-06
  • 打赏
  • 举报
回复
只记得在 DOS 时代用过这个函数,现在 Windows 系统我都不知道还能用这个函数,早就忘记了
Windows 下一般用这些函数:
WinExec
ShellExecute
CreateProcess
梅文海 2009-02-06
  • 打赏
  • 举报
回复
用 ShellExecute 这个函数是不是更好一些,这个函数的兼容性是比较好的
hearoequal 2009-02-06
  • 打赏
  • 举报
回复
写错了
不好意思


CString strTemp;
strTemp.Format("ipconfig -all > %s", strPath);
system(strTemp);

写得太简略了
没发现是错的
呵呵

现在的问题是
>符号 导出文件
如果填写的路径不是 DOS能接受的路径名 就导不出文件

想问问有没有什么办法
因为我的路径是GetModuleFileName
得到的 是windows格式的 文件路径 不是DOS格式的文件路径
dxk01 2009-02-06
  • 打赏
  • 举报
回复
不知道LZ用的是什么库的system函数,我知道的只带一个参数
thinkboy234 2009-02-06
  • 打赏
  • 举报
回复
第一步: dir >1.txt (注:这个命令是把当前目录列表生成一个文本文件)
第二步: edit 1.txt(注:编辑这个文本文件,把其它无关的都删除掉,只留下中文文件夹的ASCII码,在这个ASCII前面加上cd 空格,然后,保存,退出)
第三步:ren 1.txt 1.bat (注:这个命令是将1.txt的文本文件改成1.bat的批处理文件)
第四步:1回车(注:执行1.bat的批处理文件)

64,648

社区成员

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

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