Forum Discussion

NisHera's avatar
NisHera
Valued Contributor
9 years ago
Solved

write text file from command prompt

if I run below in TC works fine ...could see cmd prompt restarting server

Sys.OleObject("WScript.Shell").Run("iisreset MyComputer");

if I type below in cmd prompt and manually run it works 

iisreset MyComputer >C:\Myfolder\.........\iisRestarted.txt

But if I run below in TC it dosnot work

Sys.OleObject("WScript.Shell").Run("iisreset MyComputer >C:\\Myfolder\\.........\\iisRestarted.txt");

how should I make it works? there are no spaces in file path

  • Add "cmd /c" at the beginning of your command:

    Sys.OleObject("WScript.Shell").Run("cmd /c iisreset MyComputer > C:\\MyFolder\\iisRestarted.txt");

    Output redirection is a feature of the command shell (cmd.exe), so you need to run your command via cmd.

     

    Also make sure you run TestComplete as administrator, as required by iisreset.

3 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Add "cmd /c" at the beginning of your command:

    Sys.OleObject("WScript.Shell").Run("cmd /c iisreset MyComputer > C:\\MyFolder\\iisRestarted.txt");

    Output redirection is a feature of the command shell (cmd.exe), so you need to run your command via cmd.

     

    Also make sure you run TestComplete as administrator, as required by iisreset.

  • marcoxvid's avatar
    marcoxvid
    New Contributor
    hello , if I understand your need, you could also use the command:

    aqFile.WriteToTextFile

     

  • mailnsuresh's avatar
    mailnsuresh
    Occasional Contributor

    You can make a .bat file for your commands and then run the file. That will also work.