51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 3573|回复: 9
打印 上一主题 下一主题

[原创] 请问我的调用dos命令错在哪里

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2007-5-15 15:12:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
今天想要用qtp 在dos下面输入
net start "Trend Micro InterScan WebProtect Console"
问了人,写了这样一句话,可是始终不能启动服务,不知道错在哪里,还请各位帮帮忙
qtp的语句为:
oshell.run "cmd /k CD C:\& net start "&"""&"Trend Micro InterScan WebProtect Console"&"""
谢谢大家
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2007-5-15 15:24:56 | 只看该作者
给的语句太简单了,没有上下文也没有出错信息。
如果单凭这一个语句,QTP无论如何也不能正常运行啊。oshell是什么,初始化了吗?QTP提示的错误信息呢
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2007-5-15 15:43:22 | 只看该作者
都初始化了,我试了启动另一个进程的服务名,叫iswp-main,dos命令行启动为:net start iswp-main
qtp语句为:oshell.run "cmd /k CD C:\& net start iswp-main“,没有错误
可是因为这个服务名有空格:trend micro interscan webconsole,所以dos下面必须输入
net start ”trend micro interscan webconsole“,这个引号怎么在qtp下输入呢?
回复 支持 反对

使用道具 举报

该用户从未签到

4#
 楼主| 发表于 2007-5-15 15:56:03 | 只看该作者
不好意思,这是我的代码,还请高手指教。
   qtp代码:
  Dim oshell
   
   Set oshell=createobject("Wscript.shell")
   oshell.run "cmd /k CD C:\& net start"&" "&"""&"Trend Micro InterScan WebProtect Console"&"""
   Set oshell=nothing

dos窗口下,想输入的命令为:net start "Trend Micro InterScan WebProtect Console"
不知道我的qtp命令哪里错了呢?谢谢大家
回复 支持 反对

使用道具 举报

该用户从未签到

5#
发表于 2007-5-15 16:32:09 | 只看该作者
其实你的问题就是如何在VBScript中实现双引号。一个字符创的双引号可以写成chr(34),这样脚本里面的关键语句如下:
oshell.run "cmd /k CD C:\& net start " & chr(34) & "Trend Micro InterScan WebProtect Console" & chr(34)
sdlkfj2
回复 支持 反对

使用道具 举报

该用户从未签到

6#
 楼主| 发表于 2007-5-15 16:50:26 | 只看该作者

非常感谢!

真的是这样,原来我一直没有找到怎样实现双引号的转变的问题:
chr(34),问题解决了,谢谢了。感激不敬!
回复 支持 反对

使用道具 举报

该用户从未签到

7#
 楼主| 发表于 2007-5-15 16:59:40 | 只看该作者
谢谢winfood。还有给与帮助的xiaonan,wssgily,调了n久,终于解决了。
回复 支持 反对

使用道具 举报

该用户从未签到

8#
发表于 2007-5-15 17:22:06 | 只看该作者
这样可以吗?:oshell.run  "cmd /k CD C:\& net start "&""""&"Trend Micro InterScan WebProtect Console" & """" & ""
回复 支持 反对

使用道具 举报

该用户从未签到

9#
发表于 2007-5-15 18:04:58 | 只看该作者
Four different ways to launch your application are mentioned below:

1) SystemUtil.Run
SystemUtil.Run ( FileName, Parameters, Path, Operation )
FileName - The name of the file you want to run.
Parameters - If the specified FileName is an executable file, use the Parameters argument to specify any parameters to be passed to the application.
Path - The default directory of the application or file.
Operation - The action to be performed. If this argument is blank (""), the open operation is performed.
The following operations can be specified for the operation argument of the SystemUtil.Run method:
open - Opens the file specified by the FileName parameter. The file can be an executable file, a document file, or a folder. Non-executable files are open in the associated application.
edit - Launches an editor and opens the document for editing. If the FileName argument does not specify an editable document file, the statement fails.
explore - Explores the folder specified by the FileName argument.
find - Initiates a search starting from the specified folder path.
print - Prints the document file specified by the FileName argument. If the specified file is not a printable document file, the statement fails.
Example:SystemUtil.Run "D:\My Music\Breathe.mp3","","D:\My Music\Details","open"

2) InvokeApplication
This command is now mainly used for the backward compatability ie to use with the lower versions(below QTP 6.0) of QTP.
InvokeApplication("Full URL as Parameter")
Example:InvokeApplication "C:\Program Files\Internet Explorer\IEXPLORE.EXE http://www.yahoo.com"

3) VBscript to invoke application
1. Create a "WScript.shell" object.
2. Use the "run" object to launch the application. If the path to your executable contains spaces, use Chr(34) to ensure the path is contained within double quotes.
3. When done, set the shell object to nothing to release it.
Example:
Dim oShellSet oShell = CreateObject ("Wscript.shell")'
Example 1 - run a batch file:oShell.run "F:\jdk1.3.1\demo\jfc\SwingSet2.bat"'
Example 2 - run a Java jar file:oShell.run "java -jar F:\jdk1.3.1\demo\jfc\SwingSet2\SwingSet2.jar"'
Example 3 - launch Internet Explorer:oShell.Run Chr(34) & "C:\Program Files\Internet Explorer\IEXPLORE.EXE" & Chr(34)Set oShell = Nothing

4) Trivial but useful method
If nothing works out you might try this
You can use the Start -> Run dialog of Windows.
1. Add the Windows Start button to the Object Repository using the "Add Objects" button in Object Repository dialog.
2. Open the Run dialog (Start -> Run), and learn the "Open" edit field and the "OK" button into the Object Repository.
3. Switch to the Expert View, and manually add the lines to open the Run dialog.
Example:Window("Window").WinButton("Button").ClickWindow("Window").Type("R")
4. Manually enter the lines to enter the information to launch the application, and click the "OK" button of the Run dialog.
Example:
Dialog("Run").WinEdit("Open:").Type "c:\WINNT\system32\notepad.exe"
Dialog("Run").WinButton("OK").Click

[ 本帖最后由 zbyufeifei 于 2007-5-15 18:06 编辑 ]
回复 支持 反对

使用道具 举报

该用户从未签到

10#
发表于 2007-5-17 13:34:03 | 只看该作者
LZ也可以把3个双引号的地方换成4个就行
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-9-29 05:33 , Processed in 0.099987 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表