I exported my Processing project, which renders as P3D, successfully. The .exe file works, even from the command line. I need to run this executable from a c++ program. When I call
system("Project_name.exe");
on it, it doesn't open up the file. I checked the path by opening other types of files like .txt successfully. I also tried it with system("start Project_name.exe")and it gives the same input.
Is it because its not reading java with the app properly? The java folder is also in the same directory. I am using VS 13 Pro. Please help!
Note: I understand system calls are not the best approach. I also used CreateProcess but was not successful. I think the file is opened but the frame and contents doesn't display.
Thank you
System command works fine in case of interactive applications, starting notepad works fine.
Please ensure your application and dependencies are picked up from the right path, You may try to set path environment variable within c++ application.
If you are able to run this application from command line, you may write a batch file to invoke your application and invoke this batch file from c++ application using system command
Related
I am trying to use EXECUTE_COMMAND_LINE (Fortran) in Code::Blocks to start a program through a shortcut with the Windows command prompt. I have checked the path and the syntax several times, and everything is correct, however whenever I compile and run the code, when the script reaches this command I get an error saying that "The specified path does not exist. Check the path and then try again.".
Even more peculiar is the fact that, using the exact same command within the EXECUTE_COMMAND_LINE directly in the command prompt successfully launches the application with no problems whatsoever.
The command I use is the following:
CALL EXECUTE_COMMAND_LINE("start C:\Users\dimpa\Desktop\Giannako\Optimization\VBA\SLDA.lnk")
I run Windows 10, Code::Blocks 20.03 and have the MinGW compiler for Fortran.
Have also used SYSTEM with exactly the same results. Also, if it is to any use helping me figure out what is going on, this command works just fine:
CALL EXECUTE_COMMAND_LINE("start C:\Users\dimpa\Desktop\Giannako\Optimization\VBA")
Opening the folder VBA to my File Explorer. The problem seems to be related with opening the shortcut of the application. Further more, opening files located in dimpa\Appdata folder (original .exe, not the shortcut) seems to be working even through the IDE, where anything in Program files is inaccessible.
Thanks in advance.
Cheers, after endless experimentation, I seem to have found a workaround.
The problem was revolving around spaces being included in the path of the original program of the shortcut in use. Apparently the compiler isn't fond of executing shortcuts, which might initially not contain spaces in the initial path, but when redirected to the original program can run into all sorts of things.
The shortcut that I was trying to execute contained a path leading into Program Files and opened an additional addon to be executed in the aforementioned program ("/m"). After realizing that trying to run a shortcut with a 150 string length target could complicate things, I directly entered the target of the shortcut into the Windows cmd, which worked perfectly fine and was much more easier to dissect and be examined in order to properly write the code:
CALL SYSTEM(""Full Path to Program" "/m" "Full Path to Addon"")
Hope this helps someone facing similar issues!
I created a Win32 C++ console application. I want to run some CMD scripts instead of building and running this app. How can I do that?
Exactly what commands do you want to run?
Depending on the complexity of your logic, it's ok to scrap your Win32 C++ console application and just use "Batch files". (That's assuming you are running on a Windows operating system that is Windows 7 or earlier versions).
Batch files have a myriad of operations and operators that you can use to execute commands and even has some logic structures and ability to pass in parameters and call other batch files as if they were sub procedures.
You'd do best buying a book on Batch files.
Also you can google:
"Batch files",
"DOS Files", and
"Win32 Shell Scripting" to get tutorials on all the in's and out's of writing a batch file.
You can use any text editor to write a batch file (like note pad, etc). In order to make it a batch file, you name the file with a .bat extension.
By running the batch file in a command prompt window, the computer will execute the commands in the file as if you were typing them into the prompt yourself.
The one drawback is that Batch files are much slower than other compiled languages. But if speed and memory size is not an issue, then there is nothing wrong with using them.
Give us more details if you want more of an explanation.
Best of luck :)
I have a programmable signal generator. It came with a .inf file and a .exe file. Double clicking the .exe file runs the signal generator systems application.
I would like to invoke this executable from a piece of VC++ code. I am using Shell Execute as follows.
std::string app = "C:\gen.exe";
ShellExecute(NULL,"open",NULL,app.c_str(),NULL,SW_SHOWNORMAL);
However, instead of launching the executable, the command pops open a file dialog.
Upon further experimenting with ShellExecute, I noticed that ShellExecute works for executable files in the Program Files directory, but fails when I have stand alone executables such as in the case I mentioned above. Can someone please explain how to launch using VC++ a standalone executable located in a random directory on the disk?
By Standalone executable, I mean that the binary distribution for the application was simply an executable file, and a couple of other files. I can launch the executable by simply double clicking it, however, I cannot launch it using ShellExecute.
If you take a look at the documentation for ShellExecute (link), it seems like you might have the reference to app in the wrong parameter. The fourth parameter is the parameters parameter - not the parameter specifying which file to open/run. So basically, this should work:
std::string app = "C:\\gen.exe";
ShellExecute(NULL,"open",app.c_str(),NULL,NULL,SW_SHOWNORMAL);
Alternatively, you could use CreateProcess or system("C:\\gen.exe");. I should point out that none of these options are portable to other OSs, but running a program probably won't be, however you end up doing it, since most OSs differ on how they run programs - or even what programs are.
I have a rather interesting problem I've been trying to find a way to solve, and as of the moment, I have not found a solution to. I currently have built a GUI program using Python, and more specifically using Tkinter, which will generate a file with a list of commands to be repeated by my program in the specified order while waiting however long is specified. It's basically used to create a macro, which is recorded in a file and can be ran later using another function in the program.
What I would like to add to my program is a manner in which to create an .exe file, which is a standalone file, that can run a script from within it. The reason I can not find a good way to do this though is because I need for it to be created on the fly. What I was thinking I'd like to do is generate an .exe(Standalone macro exe) with PyInstaller ahead of time, and package this in to my main .exe also using PyInstaller. When you choose the option to create a standalone macro, it would proceed to get the .exe(Standalone macro exe) which I had packaged in to my main .exe from the directory in which it was unpacked in to when the program was run, copy it to the desired location for the standalone exe to be saved to, and then copy the script the user wished to be run as a standalone and package it in to the standalone exe.
I have no idea how to go about this, because I'm not sure exactly how PyInstaller puts the files in to a .exe when it packages it. Because of that, I wouldn't know how to add a file to an existing .exe using python.
Basically what I need help with is how I might go about adding a text file to an .exe generated by PyInstaller.
Ummm,
Could you clarify something...are you thinking something like Perl's (25th birthday today) (camel book by Larry Wall, p44) handles or a Bash HERE document ?
Update (based on discussion below): This will integrate python files and other externalities into a single installable:
http://www.pyinstaller.org/export/d3398dd79b68901ae1edd761f3fe0f4ff19cfb1a/project/doc/Manual.html?format=raw#create-a-spec-file-for-your-project
http://www.pyinstaller.org/export/d3398dd79b68901ae1edd761f3fe0f4ff19cfb1a/project/doc/images/SE_exe.png
I wrote mfc c++ console application. This Application is using "a dll" and this dll use one "xml file" for store some datas.
I need multiple process for my design and also I can start multiple process from my application at the start time with "Windows Service Application".They are running as a "System Process".They work nice.
Normally if my application runs as a user process,XML File is created in same directory with process. But If it runs as System process, XML File is created in "C:\Windows\SysWOW64" folder by dll. So all processes are using same xml file.
Problem is Dll wasn't written by me so i cant change anything on it. Can i do something for this?
My OS is "Windows Server 2008 R2"
thnx in advance
During installation of service, you can set command line parameter for example: -directory c:\MyAppFolder. In your application get this parameter and change working directory by SetCurrentDirectory method. Dll you are calling creates xml file in working directory, which will be c:\MyAppFolder. If you create more services make sure each of them has unique directory.