【问题标题】:Line break in an input box?输入框中的换行符?
【发布时间】:2021-11-27 13:25:13
【问题描述】:

我写了一个需要输入框的批处理脚本,首先是代码行:

powershell -Command "& {Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::InputBox('Enter your command: [*here i want a line break*] Example commands: [*and here i want a line break*] example command', 'Input box example')}" > %TEMP%\out.tmp

如何在此处插入换行符?请帮助我,现在搜索几个小时。

亲切的问候, jcjms

【问题讨论】:

  • jcjms,我已经删除了你的一些标签。这个问题仅与您的 [powershell] 代码的一小部分有关,并且与使用特定布局设计 [inputbox] 相关。它与 [batch-file]、[command-prompt] 或 [messagebox] 无关。在为您的问题分配标签时,请多加考虑。

标签: powershell inputbox


【解决方案1】:

你可以这样做:

powershell -Command "& {Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::InputBox(\"Enter your command: `r`nExample commands: `r`nexample command\", 'Input box example')}"

powershell -Command "& {Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::InputBox('Enter your command: {0}Example commands: {0}example command' -f [environment]::Newline, 'Input box example')}"


正如mklement0 评论的那样。
无需将命令包含在& {..} 中。您可以简单地在命令周围加上引号:

powershell -Command "Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::InputBox(\"Enter your command: `r`nExample commands: `r`nexample command\", 'Input box example')"

powershell -Command "Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::InputBox('Enter your command: {0}Example commands: {0}example command' -f [environment]::Newline, 'Input box example')"

【讨论】:

  • @jcjms 不客气!
猜你喜欢
  • 2019-12-07
  • 1970-01-01
  • 2010-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-19
相关资源
最近更新 更多