string - 在 dart 中的字符串内使用双引号会导致不需要的结果
问题描述
FLUTTER 和 IDE 信息(如果您有更多信息,请告诉我)顺便说一句,尽管 Flutter 医生说了什么,我使用的是 Android Studio 4.2.2(2021 年 6 月 24 日版本)。
C:\Users\Administrator>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19041.1052], locale tr-TR)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.9.4)
[!] Android Studio
X android-studio-dir = C:\ProgramFiles\Android\Android Studio
X Android Studio not found at C:\ProgramFiles\Android\Android Studio
[√] VS Code (version 1.57.1)
[√] Connected device (3 available)
Dart SDK version: 2.13.4 (stable) (Wed Jun 23 13:08:41 2021 +0200) on "windows_x64"
我想要的是,我正在创建一个字符串以将其用作Process.Run中的参数。我正在使用命令行来触发FastCopy(Windows 中最快的复制工具,并且有一个非常好的队列过程)。我需要在不破坏代码的情况下使用双引号,因为如果不使用双引号(“)打开和关闭,FastCopy 将无法在文件夹名称中有空格的情况下工作
这是示例:
String path : r"C:\Users\Administrator\Desktop\sample.txt"
String output: r"C:\"
// This will not cause any problems because folder names have no space
// This has no double quote
Process.run("cmd",
['/c start /wait C:\\Users\\Administrator\\FastCopy\\FastCopy.exe /cmd=force_copy /auto_close /estimate=TRUE $path /to=$output'],
runInShell: true,);
现在,当我在变量之前和之后放置双引号(“)时:
String path : r"C:\Users\Administrator\Desktop\sample.txt"
String output: r"C:\"
// This has double quote in it
Process.run("cmd",
['/c start /wait C:\\Users\\Administrator\\FastCopy\\FastCopy.exe /cmd=force_copy /auto_close /estimate=TRUE "$path" /to="$output"'],
runInShell: true,);
如果我将参数部分输出为字符串,则结果是预期的输出字符串。控制台显示它应该是什么。当我自己从 cmd 控制台运行它时,它按预期工作。但是当我在颤振中运行它时,它会在字符串之前添加另一个“C:”所以它变成
C:\C:\Users\Administrator\Desktop\profanity_TR.txt
它会引发目录错误。错误来自我链接的 FastCopy.exe。
目前,我使用的是无引号版本并且没有错误。但我真的很想解决这个问题,因为将它与名称中有空格的目录一起使用并且不想遇到此类问题。
解决方案
推荐阅读
- android - 如何检查表是否已存在
- java - 单击按钮时如何动态更改BorderPane中心的视图?
- html - 为什么我的导航栏图标没有出现在我的网站上?
- jupyter - JupyterLab 和 JupyterHub 有什么区别?
- google-app-engine - 网站托管在 App Engine 上,如何访问云存储中的图像?
- php - 使用 HTML2PDF 创建 A4 PDF 时出现 css top 属性问题
- java - 无法将战争文件部署到 Weblogic 12c 服务器上的特定文件夹
- c# - 如何在没有列名的情况下序列化 sql 数据?
- gradle - Gradle 子项目依赖项无法由需要它的项目解决
- javascript - (JavaScript & HTML )将项目从一个列表移动到另一个列表