Inno command line compilation not working - c#

I'm trying to compile .iss file with command line
string INNOCLI = Application.StartupPath + #"\Inno\ISCC.exe";
string Argument = string.Format("iscc /q \"{0}\"", INNOSCRIPTFILE);
using (Process cli = new Process())
{
//cli.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cli.StartInfo.FileName = INNOCLI;
cli.StartInfo.Arguments = Argument;
cli.StartInfo.UseShellExecute = false;
cli.StartInfo.RedirectStandardError = true;
cli.StartInfo.RedirectStandardOutput = true;
//cli.StartInfo.CreateNoWindow = true;
cli.OutputDataReceived += cli_OutputDataReceived;
cli.ErrorDataReceived += cli_ErrorDataReceived;
cli.Start();
cli.BeginErrorReadLine();
cli.BeginOutputReadLine();
cli.WaitForExit();
}
But i'm getting nothing out of it, i'm using c#
Edit:
I disabled output redirect, now i see its saying "Script file name specified more than once" on console window.

You've said that the output you get from the ISCC tool that you execute is:
Script file name specified more than once
which comes from this exception which is raised if you pass more than one parameter longer than 1 char with no starting /, or - char. And that's what happens because you have mistakenly passed iscc and a file name to your arguments. Remove that mistyped iscc from there. Change this line:
string Argument = string.Format("iscc /q \"{0}\"", INNOSCRIPTFILE);
to this:
string Argument = string.Format("/q \"{0}\"", INNOSCRIPTFILE);

I was experiencing this issue and the fix for me was to specific the script file as the very first argument.

Related

execute Sqlite3 command line tool from code

I'm trying to run the sqlite.exe tool as a process in my c# code in order to read a sql from a file.
If I run the sqLite3 tool in powershell then it works fine (sqlite3.exe "mydatabase.db" ".read mySql.sql")
But when I run the sqlite3 tool from my c# code as a process, then nothing happens to mydatabase.db. It's still 0b when sqlite3 terminates.
I get no error message, the output from the sqlite3.exe is an empty string and the exit code is 1 (verified in the exit event). Does anyone have a clue why the database.db why the records in the .sql file is not added to the .db file?.
using (Process pProcess = new Process())
{
pProcess.StartInfo.FileName = sqlLite3ExePath;
pProcess.StartInfo.Arguments = $"\"{sqLitePath2}\" \".read {sqlPath}\"";;
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;//System.Diagnostics.ProcessWindowStyle.Hidden;
pProcess.StartInfo.CreateNoWindow = false;//true; //not diplay a windows
pProcess.EnableRaisingEvents = true;
pProcess.Exited += PProcess_Exited;
pProcess.Start();
string output = pProcess.StandardOutput.ReadToEnd(); //The output result
pProcess.WaitForExit();
Debug.WriteLine(output);
}
As CaiusJard said in the comments, an error was passed in the error stream. Adding the following lines told me that my path was wrong.
pProcess.StartInfo.RedirectStandardError = true;
string error = pProcess.StandardError.ReadToEnd(); //The output result
The path divider "\" was removed since the path was parsed twice. Once setting the argument, and once when it was read by the tool. Replacing "\" with "/" in my paths did the trick

P4 edit not appearing to work from c# process call no error or standard output returned

I am trying to checkout some files from p4 using a cmd process call from c# but the edit command does not seem to be working. I can change the edit to the set command and get the expected results. The edit command does not return an error or standard output. If I put a working file path in the code I get the same result. The command works from a dos box if I type it in manually. I am trying to do this without the p4 net.api if possible.
Is there anything I am missing in the code below?
System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo();
proc.FileName = #"c:\windows\system32\cmd.exe";
proc.Arguments = #" /c p4 edit";
proc.RedirectStandardError = true;
proc.RedirectStandardOutput = true;
proc.UseShellExecute = false;
using (System.Diagnostics.Process process = System.Diagnostics.Process.Start(proc))
{
using (StreamReader reader = process.StandardError)
{
string result = reader.ReadToEnd();
_threadError = result;
}
}
I have also tried passing a file in the following way and get the same result as above. I would expect to at least get a standard error if not a standard output.
string Arguments = string.Format(" //c p4 edit -c default {0}", _tmp);

Using C# 4.0 to run Python scripts error non-ascii char

I eventually want to be able to return a DataFrame from Python to C#. At the moment I am running a very simple console app to try and run a basic Python script. This script compiles and runs in Canopy fine however when I run it from C# I get the error relating to non-ASCII chars.
I have read many articles relating to this but none of them seem to resolve the issue I have.
Error
SyntaxError: Non-ASCII character '\x90' in file C:\Program Files\Enthought\Canop
y32\App\appdata\canopy-1.5.2.2785.win-x86\python.exe on line 1, but no encoding
declared; see http://www.python.org/peps/pep-0263.html for details
Thx in advance for any help!
static int test_python_canopy()
{
string cmd;
string args;
args = "C:\\Share\\Python\\test.py";
cmd = #"C:\Program Files\Enthought\Canopy32\App\appdata\canopy-1.5.2.2785.win-x86\python.exe";
cmd = "\"" + cmd + "\"";
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = cmd;
start.Arguments = string.Format("{0} {1}", cmd, args);
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.Write(result);
}
}
return 0;
}
For ProcessStartInfo, FileName should be set to the executable that you wish to run and Arguments should be set to the arguments that you want to pass to that executable.
In your code, FileName is set correctly to the Python interpreter. Arguments, however, the first argument is being set to Python interpreter. The net result is that C# is trying to execute this command:
C:\Program Files\Enthought\Canopy32\App\appdata\canopy-1.5.2.2785.win-x86\python.exe C:\Program Files\Enthought\Canopy32\App\appdata\canopy-1.5.2.2785.win-x86\python.exe C:\Share\Python\test.py
which means that Python is trying to use the Python executable as a script, which is not going to work. Changing the line that sets the arguments should fix the problem:
start.Arguments = args;

C# command line SetACL

I'm trying to fix an issue with the owner on a folder. I am using SetACL. I can use cmd and make the arguments work, but when I try adding it to a program...it doesn't work. I've set a break point to ensure the argument is passed right and it was. Any help is welcome.
Process p = new Process();
if (Wow.Is64BitOperatingSystem == true)
{
p.StartInfo.FileName = "SetACLx64.exe";
}
else
{
p.StartInfo.FileName = "SetACLx86.exe";
}
string command = #" -on """ + path +
#""" -ot file -actn setprot -op ""dacl:np;sacl:nc"" -actn setowner -ownr ""n:" + account + #";"" -rec cont_obj";
p.StartInfo.Arguments = command;
p.Start();
I have got this to work in the same program for a registry issue without trouble. Just can't get this example to work. Folder I'm try to set is the %temp% folder.
If it is running as admin as Sanjeevakumar asked then
Try removing the first space in your command variable. The Arguments parameter does not require that you provide an initial space for the arguments. May be that causes the problem.
Also try tapping into the error data of your process by adding the following lines before calling the Start() method.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.ErrorDataReceived += new DataReceivedEventHandler(ErrorDataHandler);
And then define the event handler.
private static void ErrorDataHandler(object sendingProcess, DataReceivedEventArgs e)
{
//using the DataReceivedEventArgs see if there is an error.
//If it comes there there is most likely an error.
}
So your code does not work when path is "%temp%"? In that case the solution is simple: variable expansion is not done by SetACL but the command shell before SetACL is even started. If you start SetACL directly without invoking cmd.exe then variable expansion never takes place.
You have two options:
Expand "%temp%" in C# code with Environment.GetEnvironmentVariable.
Call SetACL via cmd like this: cmd /c SetACL -on %temp% -ot file ...

C#: How would I execute this command line directly to java.exe?

I am writing a program that needs to run a java.jar server. I need to run the process directly so I can rewrite the output to a textbox and all-in-all have complete control of it. I tried just doing it through CMD.exe, but that wouldnt work because CMD.exe would just call a new process java.exe and I wouldn't have control of it. I need to call java.exe directly so I can have the control and get the output. Can any of you tell me how to convert this command so I could create a process in C# and call it?
I need this CMD command converted:
"java -Xmx1024m -cp ./../libs/*;l2jserver.jar net.sf.l2j.gameserver.GameServer"
into
a command line I can put into the Process.Arguments so I can call Java.exe directly.
I've tried to do it... and it just won't work.
I've been looking at this for hours and hours... please someone help!
Part of the problem might be that despite what the Framework documentation says using Process doesn't always resolve things against the PATH environment variable properly. If you know the name of the folder Java is in then use the full path to Java.exe, otherwise use a function like the following:
private void LocateJava()
{
String path = Environment.GetEnvironmentVariable("path");
String[] folders = path.Split(';');
foreach (String folder in folders)
{
if (File.Exists(folder + "java.exe"))
{
this._javadir = folder;
return;
}
else if (File.Exists(folder + "\\java.exe"))
{
this._javadir = folder + "\\";
return;
}
}
}
It's somewhat hacky but it will find java.exe provided the Java Runtime is installed and it's folder is in the windows PATH variable. Make a call to this function the first time your program needs to find Java and then subsequently start Java using the following:
//Prepare the Process
ProcessStartInfo start = new ProcessStartInfo();
if (!_javadir.Equals(String.Empty)) {
start.FileName = this._javadir + "java.exe";
} else {
start.FileName = "java.exe";
}
start.Arguments = "-Xmx1024m -cp ./../libs/*;l2jserver.jar net.sf.l2j.gameserver.GameServer";
start.UseShellExecute = false;
start.RedirectStandardInput = true;
start.RedirectStandardOutput = true;
//Start the Process
Process java = new Process();
java.StartInfo = start;
java.Start();
//Read/Write to/from Standard Input and Output as required using:
java.StandardInput;
java.StandardOutput;

Categories