gpt4 book ai didi

node.js - 使用字符串文字有效,但作为参数传递无效

转载 作者:行者123 更新时间:2023-12-04 23:24:05 25 4
gpt4 key购买 nike

我将字符串文字传递给我的 powershell 脚本,如下所示:

var spawn = require("child_process").spawn,
child;
child = spawn("powershell.exe", [
"./scripts/ffmpeg_convert.ps1",
`./cache/videos/${tempFileName + "."}${videoType}`,
` ./cache/converted_videos/${tempFileName + "."}${videoType}`
]);

spawn 是 node.js 的一部分 Spawn

还有我的 powershell 脚本 如下:
param(
[string]$originFile = $Args[0],
[string]$outputFile = $Args[1]
)
echo "Moving moov atom"
ffmpeg -i $originFile -vcodec copy -acodec copy -movflags +faststart $outputFile

但是,脚本不会使用参数执行
./cache/videos/${tempFileName + "."}${videoType}
但是,如果我将参数更改为文字字符串,让我们说 ./cache/videos/inputVideo.mov
它执行得很好。

这真的让我摸不着头脑。

我创建了两个使用相同主体的测试脚本... 就是这样 ${tempFileName + "."}${videoType}正在翻译?话虽如此,如果我回应他们的论点,它们就是预期的。

脚本 1
 ./convert_videos.ps1 ./inputVideo.mov outputVideo.mov

脚本 2
 param(
[string]$originFile = $Args[0],
[string]$outputFile = $Args[1]
)
echo "Moving moov atom"
ffmpeg -i $originFile -vcodec copy -acodec copy -movflags +faststart $outputFile

最佳答案

我认为您遇到了如何在 Powershell 脚本中声明参数的问题。尝试以下操作:

param(
[Parameter(position = 0)]
[string]$originFile,

[Parameter(position = 1)]
[string]$outputFile
)

# For debugging, check the values in PS
echo "Moving moov atom. originFile: $originFile. outputFile: $outputFile. Working Directory: $((Get-Location).Path)"
ffmpeg -i $originFile -vcodec copy -acodec copy -movflags +faststart $outputFile

您还可以在以更 Powershell 的方式调用脚本时命名参数,尽管这不会影响您的脚本执行,但对于我们这些沉浸在 Powershell 中的人来说,它看起来更好:)
var spawn = require("child_process").spawn,
child;
child = spawn("powershell.exe", [
"./scripts/ffmpeg_convert.ps1",
"-originFile",
`./cache/videos/${tempFileName + "."}${videoType}`,
"-outputFile",
` ./cache/converted_videos/${tempFileName + "."}${videoType}`
]);

关于node.js - 使用字符串文字有效,但作为参数传递无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55973748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com