Java (Minecraft) doesnt start from c# - c#

When I copy paste the javaw.exe -arguments to console it works but, when I launch it like this it doesn't work.
string directory = "C:\\Users\\Can\\AppData\\Roaming\\.minecraft";
string java = #"C:\windows\system32\javaw.exe";
string javaLocation = "C:\\Program Files\\Java\\jre7\\bin\\javaw.exe";
string RAM = "1G";
string username = "namehere";
string token = "--session token:"+tokenGenerated;
string version = "1.6.2";
string launch = "-Xmx" + RAM + " -Djava.library.path={0}\\versions\\1.6.2\\1.6.2-natives-7453523379463 -cp {0}\\libraries\\net\\sf\\jopt-simple\\jopt-simple\\4.5\\jopt-simple-4.5.jar;{0}\\libraries\\com\\paulscode\\codecjorbis\\20101023\\codecjorbis-20101023.jar;{0}\\libraries\\com\\paulscode\\codecwav\\20101023\\codecwav-20101023.jar;{0}\\libraries\\com\\paulscode\\libraryjavasound\\20101123\\libraryjavasound-20101123.jar;{0}\\libraries\\com\\paulscode\\librarylwjglopenal\\20100824\\librarylwjglopenal-20100824.jar;{0}\\libraries\\com\\paulscode\\soundsystem\\20120107\\soundsystem-20120107.jar;{0}\\libraries\\argo\\argo\\2.25_fixed\\argo-2.25_fixed.jar;{0}\\libraries\\org\\bouncycastle\\bcprov-jdk15on\\1.47\\bcprov-jdk15on-1.47.jar;{0}\\libraries\\com\\google\\guava\\guava\\14.0\\guava-14.0.jar;{0}\\libraries\\org\\apache\\commons\\commons-lang3\\3.1\\commons-lang3-3.1.jar;{0}\\libraries\\commons-io\\commons-io\\2.4\\commons-io-2.4.jar;{0}\\libraries\\net\\java\\jinput\\jinput\\2.0.5\\jinput-2.0.5.jar;{0}\\libraries\\net\\java\\jutils\\jutils\\1.0.0\\jutils-1.0.0.jar;{0}\\libraries\\com\\google\\code\\gson\\gson\\2.2.2\\gson-2.2.2.jar;{0}\\libraries\\org\\lwjgl\\lwjgl\\lwjgl\\2.9.0\\lwjgl-2.9.0.jar;{0}\\libraries\\org\\lwjgl\\lwjgl\\lwjgl_util\\2.9.0\\lwjgl_util-2.9.0.jar;{0}\\versions\\1.6.2\\1.6.2.jar net.minecraft.client.main.Main --username " + username + " " + token + " --version " + version + " --gameDir {0} --assetsDir {0}\\assets";
launch = String.Format(launch, directory);
string text = launch;
// WriteAllText creates a file, writes the specified string to the file,
// and then closes the file.
Directory.SetCurrentDirectory(#"C:\windows\system32\");
Process.Start("javaw.exe",
Path.Combine(launch));
What am I doing wrong?

Why do you need to call Path.Combine if your whole path is in one string?
Assuming your javaw.exe is actually in C:\windows\system32\, Process.Start("java.exe", launch); should work as intended.
Source - Path on MSDN: http://msdn.microsoft.com/en-us/library/system.io.path.aspx

Just use Java's real location instead of "javaw" like "c:\programfiles\Java\jre7\bin\javaw.exe"

Related

Keeping Escape Characters in C#

I may be completely doing this wrong, or overlooking something obvious but here it goes. I am working with AWS CLI via C#. I am trying to send a command to the command line to change the instance type of the EC2
I've tried different ways of handling this, starting the string with #, single quotes encapsulating double quotes, etc. Here is what I currently have:
private static void resizeCurrentInstance(string instance)
{
string commands = "/C aws ec2 describe-instances --instance-ids " + instance;
string response = getNewProcess(commands);
JObject convertedResponse = JObject.Parse(response);
int i = 0;
string ReturnString = "";
foreach (JObject item in convertedResponse["Reservations"])
{
if (item["Instances"][i]["InstanceType"].Value<string>().Contains(".large"))
{
string sizeUpCommand = "/C aws ec2 modify-instance-attribute --instance-id" + instance + " --instance-type \"{\"Value\": \"m4.4xlarge\"}\"";
string sizeUpResponse = getNewProcess(sizeUpCommand);
Console.WriteLine("Instance Size inscrease " + sizeUpResponse.ToString());
}
else
{
string sizeDownCommand = "/C aws ec2 modify-instance-attribute --instance-id " + instance + ' --instance-type \"{\"Value\": \"m4.large\"}\"';
string sizeDownResponse = getNewProcess(sizeDownCommand);
Console.WriteLine("Instance Size decrease " + sizeDownResponse.ToString());
}
}
}
The problem comes from trying to generate the command string to send to the command line here
string sizeUpCommand = "/C aws ec2 modify-instance-attribute --instance-id" + instance + " --instance-type \"{\"Value\": \"m4.4xlarge\"}\""
This is the command as its give in the amazon docs:
aws ec2 modify-instance-attribute --instance-id i-1234567890abcdef0 --instance-type "{\"Value\": \"m1.small\"}"
I'm trying to figure out how to write a string so the Output is: "{\"Value\": \"m1.small\"}"
If you need to keep a backslash in the string, then you use \\ before the \".
But you are also missing a space after --instance-id, which would mess up the command.
So it should look something like this:
string sizeUpCommand = "/C aws ec2 modify-instance-attribute --instance-id " + instance + " --instance-type \"{\\\"Value\\\": \\\"m4.4xlarge\\\"}\""
If that doesn't work, then output sizeUpCommand to the console and inspect it to make sure it is what it should be.
Try this:
"{\\\"Value\\\": \\\"m1.small\\\"}"

Postman - how to pass data from List<string>, in memory, into -data portion of Newman command line

I need to execute Postman collection from within my C# method.
But instead of the data file, I need to pass the data directly from the method output (as List).
Here is my code:
public StringBuilder RunPostmanCall(string collectionPath, string executionFolder, string environmentPath, List<string> inputFilePath = null)
{
StringBuilder runOutputBuilder = new StringBuilder();
string runOutput = null;
ProcessStartInfo psiNpm = new ProcessStartInfo
{
FileName = "cmd",
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false
};
Process pNpmRun = Process.Start(psiNpm);
pNpmRun.OutputDataReceived += (sender, a) => runOutputBuilder.AppendLine(a.Data);
Console.WriteLine(" - Install Newman ...");
pNpmRun.StandardInput.WriteLine($"npm install -g newman");
Console.WriteLine(" - Execute Postman Script ...");
string value = $"newman run " +
$"\"" + collectionPath + "\" " +
$"--folder \"" + executionFolder + "\" " +
$"--environment \"" + environmentPath + "\" " +
$"-d \"" + inputFilePath + "\" " +
$"--disable-unicode";
pNpmRun.StandardInput.WriteLine(value);
pNpmRun.BeginOutputReadLine();
pNpmRun.StandardInput.WriteLine("exit 0");
I'm getting the following error:
bin\Debug>newman run "../../api/postman_audit.json" --folder "SearchIndex" --environment "../../api/postman_environment.json" -d "System.Collections.Generic.List`1[System.String]" --disable-unicode
I could save the output into the file, and then just use that file location in the command-line. But I would like to avoid creating a file, and read data directly from the memory.
unfortunately with -d you can only refer to a file in your filesystem.
If you are not willing to write this data directly into a file, i would suggest to set the values directly as a global variable from commandline.
Try to add this parameter to your newman run command
--global-var key=value
You can add your data into a string and add it as a global variable. You can parse it in your pre-request or test-script normally.

How do I replace PATH Environment variables to double quote + backslashes those which have spaces in C#?

Language version: C# - Operating system: Win 10 - IDE: Visual Studio
I've got a problem when letting the user set a path.
When the path is without spaces, all good. No issues.
When the path is with spaces, the CLI i'm forwarding the data to, doesn't accept it and instantly closes.
That's because it misses the right syntax (double quotes at beginning & end + double backslashes) when it arrives.
So the right syntax is:
app.exe -q MP3_128 -p "C:\\test test\\"
Since I'm using the Environment.GetFolderPath in WMF, I have no clue how to add these to its output...
How do I replace PATH Environment variables to double quote + backslashes those which have spaces in C#?
Code:
if (Settings.Default.download == "")
{
MessageBox.Show("Be sure your download path doesnt contain any spaces!");
String path = Environment.GetFolderPath (Environment.SpecialFolder.MyMusic);
String pathDouble = path.Replace("'", "\"");
Settings.Default.download = #"""C:\\Test\DOWN LOADS""";
Settings.Default.Save();
}
which been reached here in
Code:
if (Settings.Default.sm != "")
{
download.StartInfo.FileName = Settings.Default.sm;
string a = " -q " + qualitys + " -p " + Settings.Default.download + " " +
info[result.SelectedIndex].link;
Debug.Write(a);
download.StartInfo.Arguments = a;
}
The hardcoded default path set works.
But when the user changes that path using the GUI to their own likings, it's gone.
I think I'm editing the wrong code.
This code, I have edited, which only now needs a double \ after the drive:
using (var folderDialog = new FolderBrowserDialog())
{
if (folderDialog.ShowDialog() == DialogResult.OK)
{
Settings.Default.download = #"""" + folderDialog.SelectedPath + #"\\""";
Settings.Default.Save();
txb_download_folder.Text = Settings.Default.download;
}
}
But how?
A simple \ extra in the first #"\" results in \"C:\test test\\".

File.Copy from local to shared folder in server

I'm having problems when copying a .txt from a local server ("D:\AuditFiles") to a shared folder in another server ("\\PrintServer\SharedFolder"). It throws the exception:
"The filename, directory name, or volume label syntax is incorrect."
I thought it could be something with the path format, so I tried by adding to the server path an #:
#Configuration.Manager["Path"] | #"\\ServerPath\SharedFolder"
I've also tried with this format: \\ServerPath\SharedFolder... None of them worked.
By the way its not an access problem, cause i've tried to do the same thing running a command prompt from within c#:
System.Diagnostics.Process.Start("cmd.exe", "/C COPY PATH1, PATH2"); //This worked and copied the file.
I'd be greatful if someone could give me a clue of what could be the problem here. At least an advice of what to do.
Thanks in advance and sorry me bad english!
Edit:
This is the part of the code that should work:
string pathPrevDay = "D:\AuditFiles\enc_" + svr.Name + "_counts" + day.AddDays(-1).ToString("dd-MM-yy") + ".txt";
if(File.Exists(pathPrevDay))
{
File.Copy(pathPrevDay, #ConfigurationManager.AppSettings["MAIL_SERVER_PATH"]);
}
You need to escape the backslashes and indicate the name of the file in File.Copy(pathPrevDay, ConfigurationManager.AppSettings["MAIL_SERVER_PATH"]);.
Change this:
string pathPrevDay = "D:\AuditFiles\enc_" + svr.Name + "_counts" + day.AddDays(-1).ToString("dd-MM-yy") + ".txt";
to this:
string pathPrevDay = "D:\\AuditFiles\\enc_" + svr.Name + "_counts" + day.AddDays(-1).ToString("dd-MM-yy") + ".txt";
You can also use single slashes (/) instead like this:
string pathPrevDay = "D:/AuditFiles/enc_" + svr.Name + "_counts" + day.AddDays(-1).ToString("dd-MM-yy") + ".txt";

Enreco Video Rotation in Asp.Net Virtual Machine is not completing

I am developing an ASP.NET Web Api in which I need to concatenate some video clips and rotate them. I could achieve the same when I tried in my local system. When I deployed the same project to an Azure Virtual Machine I am not getting response. I am pretty sure that there isn't any issue till video concatenation because I could see the concatenated video in the expected folder. Here is the code snippet.
var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
NReco.VideoConverter.ConcatSettings set = new NReco.VideoConverter.ConcatSettings();
ffMpeg.GetVideoThumbnail(_fileNames[0], imageRootPath + tobename + ".jpg");
if (_fileNames.Count() > 1)
{
ffMpeg.ConcatMedia(_fileNames, videoRootPath + tobename + "_r.mp4", NReco.VideoConverter.Format.mp4, set);
string path = HttpContext.Current.Server.MapPath("~\\bin\\");
System.Diagnostics.Process ffmpeg = new System.Diagnostics.Process();
ffmpeg.StartInfo.FileName = path + "\\" + "ffmpeg.exe";
ffmpeg.StartInfo.Arguments = "-i " + videoRootPath + tobename + "_r.mp4" + " -c copy -metadata:s:v:0 rotate=90 " + videoRootPath + tobename + ".mp4";
ffmpeg.Start();
ffmpeg.WaitForExit();
}
ffmpeg.ConcateMedia is working fine. I can't figure out why the External process that I have invoked does not complete. The same piece is working fine in my local Visual Studio.
Thank you in advance
It seems you are using Nreco VideoConvertor for joinging videos and external process to rotate the video.
You can always use Invoke method to write the custom commandline. something like this
ffMpeg.Invoke("-i " + videoRootPath + tobename + "_r.mp4" + " -c copy -metadata:s:v:0 rotate=90 " + videoRootPath + tobename + ".mp4");
Hope this Helps...
Your path ends with a slash, and when adding the paths together you also add a slash.
Use Path.Combine:
string path = HttpContext.Current.Server.MapPath("~\\bin");
ffmpeg.StartInfo.FileName = System.IO.Path.Combine(path, "ffmpeg.exe");

Categories

Resources