我正在使用终端运行 Stata。有没有办法使用 Stata 在终端中打印或显示报表?
例如,我可以在终端中运行以下命令:
stata-mp -b do test.do
其中 test.do 包含以下内容:
display "Hello world"
理想情况下,我希望字符串出现在终端中,但它不会出现在终端中。它仅在 test.do 运行完成后生成的 test.log 文件中可用。
在批处理模式下,Stata 会抑制所有屏幕输出,因此您要求的是不可能的事情。
您可以使用 AppleScript 完成类似的事情。以下是 MacOS 短信/文本和通知的示例。您可以将其扩展到 Slack、电子邮件等。
// This line attempts to display "Hello world", but only visible in the log file
display "Hello world"
// This line attempts to run a shell command to echo "Goodbye world", but it
// does not work in batch mode
shell echo "Goodbye world" // does not work
// Capture and drop any existing program named 'dm' to avoid conflicts
capture program drop dm
// Define a new program named 'dm'
program define dm
// Expect anything as input syntax
syntax anything
// Remove any double quotes from the input message
local message = subinstr(`"`anything'"', `"""',"", .)
// Send the message as a text to a specified phone number using AppleScript
// CHANGE THIS to country code followed by a phone number
shell osascript -e 'tell application "Messages" to send "`message'" to buddy "12048675309"'
// Display a notification with the message and title "Stata" using AppleScript
shell osascript -e 'display notification "`message'" with title "Stata"'
end
// Call the 'dm' program with the message "Step A done"
dm "Step A done"
// Pause the execution for 4000 milliseconds (5 seconds)
sleep 5000
// Call the 'dm' program with the message "Step B done"
dm "Step B done"
dm "All done!"