我需要在周期中多次启动程序 jphide (https://github.com/h3xx/jphs)
例:
jphide input-jpeg-file output-jpeg-file file-to-hidden
我尝试使用命令行将参数传输到程序
public static void Hide(string imagePath, string passWord)
{
Collection<PSObject> results;
string fullPath = System.IO.Path.GetFullPath(imagePath);
string pathToOutFile = ".\\outImages\\" + imagePath;
pathToOutFile = System.IO.Path.GetFullPath(pathToOutFile);
System.IO.File.WriteAllLines("test.txt", new string[] { passWord });
string hiddenFile = System.IO.Path.GetFullPath(@".\test.txt");
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
runspace.Open();
RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);
Pipeline pipeline = runspace.CreatePipeline();
//Here's how you add a new script with arguments
Command myCommand = new Command(@".\script.bat");
CommandParameter pathParameter = new CommandParameter(fullPath);
CommandParameter passWordParameter = new CommandParameter(passWord);
CommandParameter pathToOutputFileParameter = new CommandParameter(pathToOutFile);
CommandParameter pathToHiddenFileParameter = new CommandParameter(hiddenFile);
myCommand.Parameters.Add(pathParameter);
myCommand.Parameters.Add(passWordParameter);
myCommand.Parameters.Add(pathToOutputFileParameter);
myCommand.Parameters.Add(pathToHiddenFileParameter);
pipeline.Commands.Add(myCommand);
// Execute PowerShell script
results = pipeline.Invoke();
}
script.bat
jphide "%1" "%3" "%4"
%2
%2
但是在行不通。执行后该程序 jphide input-jpeg-file output-jpeg-file要隐藏的文件 问我密码短语2次
C:\Users\Kostyaj\Downloads\JpegTest\JpegTest\JpegTest\bin\Debug>jphide 067.jpg 068.jpg test.txt
Welcome to jphide Rev 0.51 (c) 1998 Allan Latham <alatham@flexsys-group.com>
This program is freeware.
No charge is made for its use.
Use at your own risk. No liability accepted whatever happens.
Contains cryptogaphy which may be subject to local laws.
Passphrase:
Re-enter :
我需要手动输入
我如何编写脚本或更改C#代码以自动输入Passphrase并重新输入?
UPD
此代码
var info = new ProcessStartInfo("cmd.exe");
info.UseShellExecute = false;
info.RedirectStandardInput = true;
var process = Process.Start(info);
Thread.Sleep(1000);
process.StandardInput.WriteLine("jphide \"" + pathParameter.Name + "\" \"" + pathToOutputFileParameter.Name +
"\" \"" + pathToHiddenFileParameter.Name + "\"");
process.StandardInput.WriteLine("echo " + passWord);
在命令行中创建此输出:
jphide "C:\Users\Kostyaj\Downloads\JpegTest\JpegTest\JpegTest\bin\Debug\067.jpg" "C:\Users\Kostyaj\Downloads\JpegTest\JpegTest\JpegTest\bin\Debug\outImages\067.jpg" "C:\Users\Kostyaj\Downloads\JpegTest\JpegTest\JpegTest\bin\Debug\test.txt" || echo aaa
Welcome to jphide Rev 0.51 (c) 1998 Allan Latham <alatham@flexsys-group.com>
This program is freeware.
No charge is made for its use.
Use at your own risk. No liability accepted whatever happens.
Contains cryptogaphy which may be subject to local laws.
Passphrase:
Re-enter :
C:\Users\Kostyaj\Downloads\JpegTest\JpegTest\JpegTest\bin\Debug>echo 1234
1234
但该程序已停止等待PassPhrase的输入。我输入了它,执行继续
我需要在程序jphide中自动输入“1234”
答案 0 :(得分:0)
如果您重定向标准输入,则可以写入标准输入以填写密码,例如:
var info = new ProcessStartInfo("cmd.exe");
info.UseShellExecute = false;
info.RedirectStandardInput = true;
var process = Process.Start(info);
Thread.Sleep(1000);
process.StandardInput.WriteLine("echo Hello World");