求救--winexec()调用中的问题(100分)

  • 主题发起人 smallbee
  • 开始时间
S

smallbee

Unregistered / Unconfirmed
GUEST, unregistred user!
[green]如下面这个程序,怎么无法向temp.txt写东西啦?
也就是可以执行arp -a这个命令,但是,无法写入文件。

var
command:string;
temp:string;
begin

temp:='c:/temp.txt';
command:='arp -a>'+temp;
try
winexec(PChar(command),SW_SHOW);
except
end;

end;
[/green]
[red]拜托各位大侠了。[/red]
 
加一个空格试试
 
一般不会的。
 
WinExec这个涵数只不过是与16位的操作系统保持兼容,在Win32下请用这个
ShellExecute()
有关使用,在MSDN中有非常详细的说明
注意:Uses ShellAPI
 
去掉TRY,为什么要加TRY???
 
这是我写的调用ShellExecute的执行模块:
function ExecuteFile(Exe,Para:string;var handle:Thandle):boolean;
var Pexe,Ppara:array[0..79] of char;
begin
StrPCopy(Pexe,Exe);
StrPCopy(Ppara,para);
Handle:=ShellExecute(GetActiveWindow,'open',Pexe,Ppara,'',SW_NORMAL);
result:=true;
If handle <=32 then
begin
showmessage(Exe+'的错误代码:'+' '+Inttostr(handle));
result:=false;
end;
end;
但是这个时候
当设置exe:='arp';
para:='-a > temp.txt';的时候,照样无法生成temp.txt文件。
请问:为什么啦?
调用模块不用写了吧。
 
该散分了
 
你用了“>”这个东西, 我以前已经试过很多次, 发现winexec、ShellExecute解释命令
行的时候, 会把“>”以及它之后的东西忽略掉, 怎么努力都这样。
例如: arp -a > c:/temp.txt 解释为:arp -a
但是直接在MS-DOS方式(win98)或者命令行方式(win2000)下却执行得好好的。
问题就在这里。
不知哪为大虾能搞定这个问题, 咱洗耳恭听。 [:)]
 
把命令写在.bat文件中,然后调用那个文件就可以了
 
32位的Windows用shellexecute.
 
我以前用的时候也出现过不能执行的情况非常奇怪的是在这个括号里后面加一个空格
就行了不妨试一试。
 
to finalrinoa:
谢谢, 这个方法还可以。[:)]
 
finalrinoa 答案可用。
各位不妨试试。
不过因为10人参与了,所以给每个人10分。不要介意哦。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部