I'm new to programming and C#, I am attempting to write a program that detects errors or server crashes from my battlefield 2 server, it will then shut the server down (if the server is not already down) and start it back up but I have ran in to a small bump. When I try to start battlefield 2 back up again I receive this error from bf2:
Debug assertion failed! Version 1.0.2446.12 Build date:
Module: Python
File:
c:\dice\Projects\BF2Branches\BF2Demo\Code\BF2\Game\Python\PythonHost.Cpp
Line:243
Text: couldn't import the bf2 module:
Current confile:
The path in the error doesn't exist.
I have researched a couple different ways to start up an application but they all have the same results. These are a couple I have tried so far:
Process proc = new Process();
proc.StartInfo.FileName = #"txtServerPath.Text";
proc.Start();
and
Process.Start(txtServerPath.Text);
When I manually start the bf2 Server it starts fine. So what am I doing wrong?
My program will be ran from both Windows Server 2003 and Windows 7 if that matters.
Debug assertion failed! Version 1.0.2446.12 Build date: Module: Python File:
c:\dice\Projects\BF2Branches\BF2Demo\Code\BF2\Game\Python\PythonHost.Cpp
Line:243
Text: couldn't import the bf2 module:
Current confile:
The path in the error does not exist because it is the path on the machine on which PythonHost.cpp was written. 'Debug assertion' means that the developer of the code put a condition check at the specified line number in the cpp file to check for a certain condition to be sure that 'everything works fine.' but obviously it isn't. It seems strange though that BF2 has installed a debug version.
Anyhow, your process does start but it errors out. And the problem, it seems is that it is unable to find a python module named 'bf2' when you start the process from within C#.
So first and foremost verify that {BF2 Install folder}\python\bf2\ __init__.py exist.
In order to gain more insight on why this might be happening, try to start BF2 like this (assuming your C# application is a console application):
Process bf2 = new Process();
bf2.StartInfo.FileName = #"C:\Program Files\EA Games\Battlefield 2\BF2.exe";
bf2.StartInfo.Arguments = "+debugOutput 1";
bf2.StartInfo.UseShellExecute = false;
bf2.StartInfo.RedirectStandardOutput = true;
bf2.StartInfo.RedirectStandardError = true;
bf2.Start();
Console.WriteLine(bf2.StandardOutput.ReadToEnd());
Console.WriteLine(bf2.StandardError.ReadToEnd());
This should print some logs on the console going through which, I suspect, something useful can be deduced.
By the way can you post the remaining error message (i.e. after 'Current confile:' line)
Related
I have been trying to get the OWASP ZAP tool to run against my code in an automated fashion. I have been successful in writing a method that works consistently through the Text Explorer interface of Visual Studio 2017 on my local machine. However, whenever I try to have one of my automated test boxes run it using the remote testing command line tool triggered by TFS, then it always fails with Code 1, and no other error text.
I am running the same version of windows 10 locally and on the test box. I have the same version of visual studio installed on each, so I would expect them to be using the same version of VTest to run the tests. I'm not actually sure VTest is involved since I have converted to Selenium, and this is being run as a unit test anyway without a GUI component.
I have tried setting security on the .bat file and the .exe file it calls to Authenticated Users full access because I thought it could be a permissions issue.
I have looked in the event log, but there is are no details showing up in there. It is like it never happened.
I watch the test box while it is attempting to run this particular test, and it never even tries to start up a separate command window for the new zap process, it fails before that ever happens. However, it is definitely finding the correct file to run on the test box because I have tried altering the URL and get a specific error saying it can no longer be found.
I have also tried manually executing the command I am trying to run via command line and when I do it manually on the test box then it works perfectly. The TFS box is logged in and running as the user I tried the manual test as, and that user is a local admin on the box.
Because this works locally on my machine, and because I am able to successfully run the command manually on the test box, the problem component seems to be the TFS remote agent. The remote agent is successful in launching two other processes for Selenium testing, one of which is the IE driver, and the other is the WinAppDriver; the WinAppDriver has a separate command window associate with it when it launches. However, both of these processes are launched by the Selenium wrapper, I am not launching the processes myself directly.
You can see an excerpt below of the code I am using to launch the zap process. Does anyone know why it might be failing on my best box?
string ZapBatLocation = #"C:\Program Files\OWASP\Zed Attack Proxy\zap.bat";
var last_idx = ZapBatLocation.LastIndexOf('\\');
var _ZapProc = new System.Diagnostics.Process();
_ZapProc.StartInfo = new System.Diagnostics.ProcessStartInfo(ZapBatLocation.Substring(last_idx + 1), "-daemon") { WorkingDirectory = ZapBatLocation.Substring(0, last_idx), UseShellExecute = true, CreateNoWindow = false };
_ZapProc.ErrorDataReceived += ErrOutputHandler;
_ZapProc.Start();
System.Threading.Thread.Sleep(2000); // give it time to launch and die if it is going to
if (_ZapProc.HasExited)
throw new Exception($"Unable to launch ZAP process, exited with code {_ZapProc.ExitCode}.");
EDIT:
The log file seems to indicate some sort of config corruption. perhaps a security issue on a config file somewhere? Here is an extract of what appears to be the main error that appears frequently in the log:
2019-05-30 16:26:34,178 [AWT-EventQueue-0] INFO Control - New Session
2019-05-30 16:26:34,209 [AWT-EventQueue-0] INFO Control - Create and
Open Untitled Db 2019-05-30 16:26:34,240 [AWT-EventQueue-0] INFO
ENGINE - dataFileCache commit start 2019-05-30 16:26:34,240
[AWT-EventQueue-0] INFO ENGINE - dataFileCache commit end 2019-05-30
16:26:34,256 [AWT-EventQueue-0] INFO ENGINE - Database closed
2019-05-30 16:26:34,396 [AWT-EventQueue-0] INFO ENGINE - open start -
state not modified 2019-05-30 16:26:34,459 [AWT-EventQueue-0] INFO
ENGINE - dataFileCache open start 2019-05-30 16:26:34,475
[AWT-EventQueue-0] INFO ENGINE - dataFileCache open end 2019-05-30
16:26:35,615 [ZAP-cfu] ERROR ExtensionAutoUpdate - Unable to load the
configuration org.apache.commons.configuration.ConfigurationException:
Unable to load the configuration at
org.apache.commons.configuration.XMLConfiguration.load(XMLConfiguration.java:955)
at
org.apache.commons.configuration.XMLConfiguration.load(XMLConfiguration.java:908)
at
org.apache.commons.configuration.XMLConfiguration$XMLFileConfigurationDelegate.load(XMLConfiguration.java:1583)
at
org.apache.commons.configuration.AbstractFileConfiguration.load(AbstractFileConfiguration.java:324)
at
org.apache.commons.configuration.AbstractFileConfiguration.load(AbstractFileConfiguration.java:261)
at
org.apache.commons.configuration.AbstractFileConfiguration.load(AbstractFileConfiguration.java:238)
at
org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.load(AbstractHierarchicalFileConfiguration.java:184)
at
org.zaproxy.zap.utils.ZapXmlConfiguration.(ZapXmlConfiguration.java:88)
at
org.zaproxy.zap.extension.autoupdate.ExtensionAutoUpdate.getPreviousVersionInfo(ExtensionAutoUpdate.java:883)
at
org.zaproxy.zap.extension.autoupdate.ExtensionAutoUpdate.getNewAddOns(ExtensionAutoUpdate.java:902)
at
org.zaproxy.zap.extension.autoupdate.ExtensionAutoUpdate.gotLatestData(ExtensionAutoUpdate.java:1139)
at
org.zaproxy.zap.extension.autoupdate.ExtensionAutoUpdate$8.run(ExtensionAutoUpdate.java:983)
Caused by:
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:
Invalid byte 2 of 3-byte UTF-8 sequence. at
com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown
Source) at
com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown
Source) at
com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown
Source) at
com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipChar(Unknown
Source) at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
Source) at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
Source) at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source) at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source) at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source) at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
Source) at
com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown
Source) at
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown
Source) at
org.apache.commons.configuration.XMLConfiguration.load(XMLConfiguration.java:942)
... 11 more 2019-05-30 16:26:45,052 [Thread-10] INFO ENGINE -
dataFileCache commit start 2019-05-30 16:26:45,052 [Thread-10] INFO
ENGINE - dataFileCache commit end 2019-05-30 16:26:45,084 [Thread-10]
INFO ENGINE - Database closed 2019-05-30 16:26:45,193 [Thread-10]
INFO Control - OWASP ZAP 2.7.0 terminated.
I cleared out the log file, and tried to run the automated test, it failed as expected but did not put anything in the log file. I then tried manually running ZAP from the command prompt, and it filled the log file after I exited the program, including the above error.
So it looks like the ZAP log file is not actually created until after a successful start, or at least more of a start than I am getting in the automation.
I'm not really sure this can be called an answer, but the problem no longer exists, so here goes.
After a week of fighting that rather odd issue, I got pulled away on other tasks and could no longer focus on it. After two weeks I finally had time to resume looking into the problem, and to my surprise it was no longer an issue. The .bat file is now launching correctly every time, with no changes on my part.
My best guess is that windows may have gotten stuck and some windows update caused a reboot sometime over the past two weeks causing things to start working. Why I never tried a basic system reboot during all of my troubleshooting I don't know, chalk that up to stupidity.
On a side note, if anyone else is struggling with a similar issue, my next trouble shooting step was to create a custom .bat file with these contents:
echo 'hi'
pause
Then insert a call to it in code right above the call to start the ZAP .bat file. Just to see if the code could start anything at all, or if it were something specific to the ZAP .bat file.
var bt = new System.Diagnostics.Process();
bt.StartInfo = new System.Diagnostics.ProcessStartInfo("C:\\selenium\\test.bat");
bt.Start();
Its hard to place everything in the title, but I hope I can explain this as good as I can. Basicly I made a C# Console Application that reads a certain file every now and then. The Application runs on a Virtual Machine from Google Instances. Now I have created another Console Application that is capable of managing the other application, like closing them or restarting the executables.
The Issue:
When I start the Console Application by hand (manual), it works fine and reads the files like it should. I could close and open this as much as I like and it still works. The problem is when my second Console Application tries to restart the first Console Application. The restart works fine and most functions like certain ftp connections work, but it stops reading files and gives a null back as result. There happen to be no debug errors nor does it display an error on the console.
What I want is that the second application could restart my first application without making it run where some functions appear to be blocked.
The Code I use:
string loc = File.ReadAllText(Directory.GetCurrentDirectory() + "\\"+ "location.txt");
Process p = new Process();
p.StartInfo.FileName = loc;
p.StartInfo.UseShellExecute = true;
p.Start();
I tried running it as p.StartInfo.Verb = "runas"; but this has no positive result either. Could this be an issue with the Google Virtual Machine, possible firewall settings or code related issues.
Extra
This code does work on my own laptop and so does it work after restarting.
We have a legacy VB6 application that runs a separate C# EXE. The VB6 application relies on the C# application to perform a particular task. When the task is done successfully it will return with exit code 0, or 1 if failure.
This works well on our development machines (yes, we tried on more than 1 machine). But, when we tried it on the client machine it always returns a 0 exit code no matter the result of the task.
The really strange part is that this scenario has been working perfectly for about 8 months until this first happenned.
We even tried to make a simple C# 'runner app' that only calls an exe and catches its exit code. Again, it worked fine on our development machine but always return 0 on the client machine. So, we concluded that the problem is not in the VB6 program.
This is the C# 'runner app' code snippet that call the .exe program:
System.Diagnostics.Process installProcess = new System.Diagnostics.Process();
installProcess.StartInfo.FileName = this.textBox1.Text;
installProcess.StartInfo.Arguments = this.textBox2.Text;
installProcess.Start();
installProcess.WaitForExit();
MessageBox.Show("Exit code : " + installProcess.ExitCode.ToString());
And this is the C# code snippet that exit the program with custom exit code:
Environment.Exit(1);
Well, we suspect there's some configuration on the client machine OS that causes this strange behavior on the client machine.
Based on the comment from Michael Gosselin on this question, it is critical to compile your project as a "console application" and not as a "windows application".
This is a silly and tricky issue that I am facing.
The below code works well (it launches Calculator):
ProcessStartInfo psStartInfo = new ProcessStartInfo();
psStartInfo.FileName = #"c:\windows\system32\calc.exe";
Process ps = Process.Start(psStartInfo);
However the below one for SoundRecorder does not work. It gives me "The system cannot find the file specified" error.
ProcessStartInfo psStartInfo = new ProcessStartInfo();
psStartInfo.FileName = #"c:\windows\system32\soundrecorder.exe";
Process ps = Process.Start(psStartInfo);
I am able to launch Sound Recorder by using Start -> Run -> "c:\windows\system32\soundrecorder.exe" command.
Any idea whats going wrong?
I am using C# in Visual Studio 2015 and using Windows 7 OS.
UPDATE 1: I tried a File.Exists check and it shows me MessageBox from the below code:
if (File.Exists(#"c:\windows\system32\soundrecorder.exe"))
{
ProcessStartInfo psStartInfo = new ProcessStartInfo();
psStartInfo.FileName = #"c:\windows\system32\soundrecorder.exe";
Process ps = Process.Start(psStartInfo);
}
else
{
MessageBox.Show("File not found");
}
Most likely your app is 32-bit, and in 64-bit Windows references to C:\Windows\System32 get transparently redirected to C:\Windows\SysWOW64 for 32-bit apps. calc.exe happens to exist in both places, while soundrecorder.exe exists in the true System32 only.
When you launch from Start / Run the parent process is the 64-bit explorer.exe so no redirection is done, and the 64-bit C:\Windows\System32\soundrecorder.exe is found and started.
From File System Redirector:
In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64.
[ EDIT ] From the same page:
32-bit applications can access the native system directory by substituting %windir%\Sysnative for %windir%\System32.
So the following would work to start soundrecorder.exe from the (real) C:\Windows\System32.
psStartInfo.FileName = #"C:\Windows\Sysnative\soundrecorder.exe";
Old thread but providing one more possible case
In my case i was using arguments inside Process.Start
System.Diagnostics.Process.Start("C:\\MyAppFolder\\MyApp.exe -silent");
I changed it to
ProcessStartInfo info = new ProcessStartInfo("C:\\MyAppFolder\\MyApp.exe");
info.Arguments = "-silent";
Process.Start(info)
Then it worked.
One more case, similar to Ranadheer Reddy's answer, but different enough to trip me up for awhile.
I was making a simple mistake. I had this:
ProcessStartInfo info = new ProcessStartInfo("C:\\MyAppFolder\\MyApp.exe ");
info.Arguments = "-silent";
Process.Start(info);
See that space after the end of the path to the app? Yeah. It doesn't like that. It will not find your file if you include that.
The solution was to remove the extraneous space. Then it worked.
This is an easy enough mistake to make if you're converting an app from starting processes by launching "cmd.exe /c MyApp.exe -silent" to running "MyApp.exe" directly instead, which is what I was doing. I hope recording my misfortune here will help future developers.
I made new project (ASP.NET MVC Web Application) using Visual Studio Web 2013 Express Edition. Loading index page, redirects and everything works fine, except that in some part of my code I need to create Process and execute it, wait for it to finish, parse output of that external application and show that output to the user. However I get nothing. While debugging the code line by line:
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = Tool;
info.Arguments = filename + " " + avArray;
info.CreateNoWindow = true;
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
Process p = new Process();
p.StartInfo = info;
p.Start();
p.WaitForExit();
Process exits immediately, someone would say it is pretty fast program, but application needs at least 5 seconds (sometimes 20 seconds) to complete.
What I think is happening is that process is not created in the first place, as my IIS settings or whatever other settings are not allowing me to run this EXE. What do I do to change this?
I've been trying to this for the past 2 weeks, I've read probably every post about it, and tried every solution suggested. I am choosing to write on this post since it is the most recent.
First of all, I am using VS2013, testing on IIS Express, and then on IIS 8.5., the webpages version is 3, and the target framework 4.5. And I am assuming that (as with my case) the goal is to launch the process on the server.
What I learned:
Using IIS Express should allow you to run the process without problems. You can try to allow it to launch the window, or start your process through the shell just to be sure that it is actually launching (a shell window should popup and close). If this happens, verify that you are giving the correct path to to your program, etc. So far so good.
Going into the IIS 8.5 is a totally different matter. Theoretically, the bad way of doing it should be preatty straight-forward: you create an app-pool for that server, give it a high privileged account (local system or network system, for instance); go to AdministrativeTools->Services->IIS, LogOn tab, and allow interaction with the desktop. You should be able to do the same as in IISExpress, but in my case is just the same as with a low privilege account.
I actually started by trying just to use impersonation, but also was not able to launch the process with IIS8.5. EDIT: I retried this again today, and the api won't even run if I enable impersonation.
I've spent more time than I would like with this, any input on why I can't get this to work properly with IIS8.5 (#clzola: IIS Express should do the job) is very welcome.