Forum Discussion

John_Laird's avatar
John_Laird
Contributor
8 years ago
Solved

odd behavior with sys.clipboard

My goal is to pipe output from command line GNU DIFF to clipboard and then log it. My problem is that Sys.Clipboard is holding the last thing I copied to clipboard BEFORE running the script. I have v...
  • HKosova's avatar
    8 years ago

    WshShell.Run by default does not wait for the command to complete, so Log.Warning(Sys.Clipboard) happens before diff completes. To make it wait you need to specify True as the third parameter of the Run method.

    WshShell.Run(diffCmd, 0, True)

     

    Alternatively, you can use Python's built-in subprocess.check_output so you won't have to deal with the clipboard:

    import subprocess

    def diffTwoFilesToLog(file1, file2):
    output = subprocess.check_output(["C:\\Program Files (x86)\\GnuWin32\\bin\\diff.exe", file1, file2])
    output = output.decode() # convert byte-string to string
    Log.Warning(output)