Send output of command to text file

Hi,

I’m trying to get Bigfix to send the results (output) of a VBS script to a text file. It creates an empty file with no data.

waithidden cmd.exe /C “C:\Windows\System32\cscript.exe” /B “C:\Program Files\Microsoft Office\Office16\ospp.vbs” /dstatus > C:\ospp_vbs_dstatus.txt

How can I get the command’s output to echo the data?

Thanks

There’s a decent reference at https://ss64.com/nt/syntax-esc.html , but the short answer is to wrap all of the cmd.exe parameters in an additional set of doublequotes. Note this is a cmd.exe thing, not a bigfix thing, so other programs don’t handle quoted command lines the same way.

Try

waithidden cmd.exe /C ""C:\Windows\System32\cscript.exe" /B "C:\Program Files\Microsoft Office\Office16\ospp.vbs" /dstatus > C:\ospp_vbs_dstatus.txt"

“>” doesnt work well with action script. you have to put the redirection “>” in shell script , and execute the shell script.

Shell script? This is on Windows PC.

That didn’t seem to work. Still got an empty file. Thanks, though.

see this… I can’t put this in the action…

/tmp/mount_new_nas.sh > /tmp/bftask_.log
because “>” doesnt work in the action. It never worked for me.
so i have put that statement in another script.

ndelete __createfile\
createfile until END_OF_FILE\
/bin/sh /tmp/mount_new_nas.sh """+cmd_argu+""" > /tmp/bftask_new_nas.log\
END_OF_FILE\
move __createfile /tmp/_n.sh\
wait /bin/sh /tmp/_n.sh\
wait chmod 644 /tmp/bftask_new_nas.log\
delete /tmp/mount_new_nas.sh 

I am not powersehll expert. but I am assuming “>” behave same way as shell script does.

The method of using a createfile to run the script and handle redirecting output works well, is cross-platform, and works with all commands so I do like that method.

Using the quote-wrapping method I described does work specifically in the case of using cmd.exe though. The fact you got an empty file implies redirection is working, but there was no stdout output. Perhaps you got an error to stderr instead. Try

waithidden cmd.exe /C ““C:\Windows\System32\cscript.exe” /B “C:\Program Files\Microsoft Office\Office16\ospp.vbs” /dstatus > C:\ospp_vbs_dstatus.txt 2>&1"
To show the error output as well.

Edit misplaced quote

1 Like

Stderr didn’t seem to work either. Maybe wrapping this in a __createfile as a batch script?

Yeah, that would be the next idea.

If you’re gonna use powershell, use Start-Transcript -Force c:\yourpath.txt and Stop-Transcript. I use that quite a bit for action troubleshooting. An example:

// Disable wow64 redirection on x64 OSes
action uses wow64 redirection {not x64 of operating system}

delete __createfile

// CREATEFILE
createfile until END_OF_FILE

Start-Transcript -Force c:\temp\uninstall.txt

$app = Get-WmiObject -Class Win32_Product | Where-Object {
$_.Name -match “Microsoft Office”
}

$app.Uninstall()

Stop-Transcript

END_OF_FILE

delete powershell.ps1
move __createfile powershell.ps1

waithidden { pathname of file ((it as string) of value “Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell” of native registry) } -ExecutionPolicy Bypass -File powershell.ps1

That’s just a generic powershell template I got from another user on this forum; you can wrap w/e in it.

2 Likes

This is very handy thanks for providing it. I didn’t know about the transcript function, this will be great for troubleshooting.