The conversion is successfully worked but during conversion command prompt is open for a fraction of second..I dont want to show it
The code is:
string[] name = new string[all_audio_name.Count()];
string mpfile;
System.Diagnostics.Process pro = null;
mpfile = Path.GetFileName(all_audio_name[j]).Replace(".wav", ".mp3");
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
string outfile = "-b 32 --resample 22.05 -m j " + "\"" + new_path + "\\" + Path.GetFileName(all_audio_name[j]) + "\"" + " " + "\"" + new_path + "\\" + Path.GetFileNameWithoutExtension(all_audio_name[j]) + ".mp3" + "\"";
psi.FileName = HttpContext.Current.Server.MapPath("~/Dependencies/lame.exe");
psi.Arguments = outfile;
psi.UseShellExecute = false;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
pro = System.Diagnostics.Process.Start(psi); //IGNORE VARIABLE NAME
after System.Diagnostics.Process.Start(psi); line cmd prompt appear..plz suggest me to hide it..
Related
public string DecryptFile(string encryptedFilePath)
{
const string quote = "\"";
FileInfo info = new FileInfo(encryptedFilePath);
string decryptedFileName = info.FullName.Substring(0, info.FullName.IndexOf(".pgp") + 4);
//decryptedFileName = info.FullName.Replace(".pgp", "");
decryptedFileName = decryptedFileName.Replace(this.txtFolderPath, this.txtFolderPath + "\\ProcessedZip\\");
//decryptedFileName = "C:\\pgpTest\\ProcessedZip\\"+ info.Name;
decryptedFileName = decryptedFileName.Replace(".pgp", "");
decryptedFileName = quote + decryptedFileName + quote;
string encryptedFileName = quote + info.FullName + quote;
string password = "thisisnottherealpassword";
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.WorkingDirectory = this.txtFolderPath;
System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);
string sCommandLine = "gpg.exe --pinentry-mode=loopback --passphrase \"" + password + "\" -d -o --batch --verbose --yes --output " + decryptedFileName + #" --decrypt " + encryptedFileName;
process.StandardInput.WriteLine(sCommandLine);
process.StandardInput.Flush();
process.StandardInput.Close();
process.WaitForExit();
//string result = process.StandardOutput.ReadToEnd();
//string error = process.StandardError.ReadToEnd();
process.Close();
return decryptedFileName;
}
The above code works in a separate project but having it utilized by another layer of the application through binaries is not spitting out a decrypted file. I'm not sure why as no errors seem to be thrown and using the commandline string in my own command line will correctly run the process.
Any thoughts on why this could be?
I am making a C# program that will make input file an .iso file.
For example if we write C:\Users\User\Desktpo\a.txt in the textbox that I created and give a destination path for example C:\ it has to create an iso file name a in C:\.
So I downloaded PowerISO and learn about piso.exe then I made some other research about using Process.Start(); in C# so I write these lines of code:
string str = " create -o " + TextBox1.Text + ".iso -add " + TextBox2.Text + "//" ;
Process process = new Process();
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.FileName = "\"C:\PowerISO\piso.exe\"";
process.StartInfo.Arguments = str;
process.Start();
But this doesn't work.
Why?
EDIT: I am making an winform using Visual Studio 2017.
Please Note that
C:\PowerISO\piso.exe\
is not a valid C# path, the "\" before the P and the p is an escape indicater.
Either Add verbatim operator "#" before or escape it properly
edit:
In addition, you are adding extra double quotes to the FileName property.
You can check if the path is correct by asserting the file path with File.Exists method
Console.WriteLine(File.Exists(#"C:\PowerISO\piso.exe") ? "File exists." : "File does not exist.");
e.g
string str = " create -o " + TextBox1.Text + ".iso -add " + TextBox2.Text + "//" ;
Process process = new Process();
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.FileName = #"C:\PowerISO\piso.exe";
process.StartInfo.Arguments = str;
process.Start();
edit:
Verbatim operator will work, but escaping is better in my opinion.
string str = " create -o " + TextBox1.Text + ".iso -add " + TextBox2.Text + "//" ;
Process process = new Process();
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.FileName = "C:\\PowerISO\\piso.exe";
process.StartInfo.Arguments = str;
process.Start();
i want launch minecraft client with c# but my code doesnt work:
private void Startmc(String a, String b)
{
string javafolder = GetJavaInstallationPath();
string filepath = Path.Combine(javafolder, #"bin\");
Environment.SetEnvironmentVariable("APPDATA", kurulumdosyasi);
Process p = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "javaw";
psi.CreateNoWindow = true;
psi.Arguments = "-cp \"" + filepath + ".jar;" + filepath + "lwjgl.jar;" + filepath + "lwjgl_util.jar;" + filepath + "jinput.jar;\" ";
psi.Arguments += "\"-Djava.library.path=" + filepath + "natives\" -Xmx1024M -Xms512M net.minecraft.client.main.Main " + a + " " + b;
p.StartInfo = psi;
p.Start();
}
after click to login button nothing happen
Can't you just open a Process() from the main launcher in the install directory (C:\Program Files (x86)\Minecraft\MinecraftLauncher.exe)? It looks like you're trying to bypass the default behavior...what are you working on?
I need to get the following thing into the CMD in C#:
navigate to location
start ftp.exe
open server
user
password
get file
close
quit
How do I accomplish that?
Please mind that I can not use Net.FtpWebRequest for this particular task.
Is there a way to log in in one line like ftp user:password#host?
Try calling a bat file?
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = #"/c e:\test\ftp.bat";
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
process.StartInfo = startInfo;
process.Start();
Call ftp.bat file
Ftp.Bat file contains...
ftp -s:commands.ftp
Then in your commands.ftp
open <server_address>
<userid>
<password>
recv <source_file> <dest_file>
bye
Or something similar.
The solution I went with:
C#:
String ftpCmnds = "open " + folder.server + "\r\n" + folder.cred.user + "\r\n" + folder.cred.password + "\r\nget " + file + "\r\nclose\r\nquit";
//This is a custom method that I wrote:
Output.writeFile(basePath + "\\" + Util.getDateFormated(reverseDate) + "\\" + parentFolder + "\\" + folder.server + "\\", "tmp.txt", ftpCmnds);
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.WindowStyle = ProcessWindowStyle.Hidden;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
using (StreamWriter sw = p.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
Console.WriteLine("Forcing Download from " + folder.server + folder.path + " of " + file + "\n"); log += "\r\n\r\n\t\t- Forcing Download from " + folder.server + folder.path + file + "\tto\t" + basePath + "\\" + Util.getDateFormated(reverseDate) + "\\" + parentFolder + "\\" + folder.server + "\\" + file;
sw.WriteLine("cd " + basePath + "\\" + Util.getDateFormated(reverseDate) + "\\" + parentFolder + "\\" + folder.server + "\\");
sw.WriteLine("ftp -s:tmp.txt");
sw.WriteLine("del tmp.txt");
p.Close();
}
}
The only "bad" thing is that the tmp.txt file, which is availiable for the time it requires to download the file, contains the username and password of the server as plain text. :-/
I could append a random String to the name though to make it a little more secure.
I'm starting cmd as a process in C# and I want to pass a file path in the argument. How to do it?
Process CommandStart = new Process();
CommandStart.StartInfo.UseShellExecute = true;
CommandStart.StartInfo.RedirectStandardOutput = false;
CommandStart.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
CommandStart.StartInfo.FileName = "cmd";
CommandStart.StartInfo.Arguments = "(here i want to put a file path to a executable) -arg bla -anotherArg blabla < (and here I want to put another file path)";
CommandStart.Start();
CommandStart.WaitForExit();
CommandStart.Close();
EDIT:
Process MySQLDump = new Process();
MySQLDump.StartInfo.UseShellExecute = true;
MySQLDump.StartInfo.RedirectStandardOutput = false;
MySQLDump.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
MySQLDump.StartInfo.FileName = "cmd";
MySQLDump.StartInfo.Arguments = "/c \"\"" + MySQLDumpExecutablePath + "\" -u " + SQLActions.MySQLUser + " -p" + SQLActions.MySQLPassword + " -h " + SQLActions.MySQLServer + " --port=" + SQLActions.MySQLPort + " " + SQLActions.MySQLDatabase + " \" > " + SQLActions.MySQLDatabase + "_date_" + date + ".sql";
MySQLDump.Start();
MySQLDump.WaitForExit();
MySQLDump.Close();
You need to put the file path in double quotes and use a verbatim string literal (#) as SLaks mentioned.
CommandStart.StartInfo.Arguments = #"""C:\MyPath\file.exe"" -arg bla -anotherArg";
Example with an OpenFileDialog
using(OpenFileDialog ofd = new OpenFileDialog())
{
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string filePath = "\"" + ofd.FileName + "\"";
//..set up process..
CommandStart.StartInfo.Arguments = filePath + " -arg bla -anotherArg";
}
}
Update to comment
You can format your string using String.Format.
string finalPath = String.Format("\"{0}{1}_date_{2}.sql\"", AppDomain.CurrentDomain.BaseDirectory, SQLActions.MySQLDatabase, date);
Then pass finalPath into the arguments.