output to command line from windows gui program - c

I have a win32 gui based exe which is GDI based -
The program accepts command line arguments when it starts, and
I need a way to print out a message if the command line is incorrect.
At the moment, I am displaying an error message using MessageBox,
and would like to know how to print out this error message if the
user started the program from the dos command line. -
:)
ok this does what I want, but it requires me to press enter otherwise I dont see the current path displayed..
void RedirectIOToConsole()
{
int hConHandle;
FILE *fp;
AttachConsole(-1);
hConHandle=_open_osfhandle(GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT);
fp=_fdopen(hConHandle,"w");
fprintf(fp,"\ntesting\n");
fflush(fp);
_close(hConHandle);
FreeConsole();
}

Most applications that need to accomplish this will create a *.com version of their app (which will sit alongside the .exe). All shortcuts will point to the .exe, but if the user happens to type the name on a command line, then the .com version will end up executing (as CMD will search for .com files before .exe files) The .com version is often a thin wrapper which will invoke the .exe and wait for it to finish or utilize shared .dll files, but it exists purely so that output can be funneled to the proper console window and won't "release" it until the application finishes.
As an example, Microsoft's Visual Studio uses this approach:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE>dir devenv.*
Volume in drive C has no label.
Volume Serial Number is A482-59BA
Directory of C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE
07/26/2012 05:05 PM 7,680 devenv.com
07/26/2012 07:08 PM 406,976 devenv.exe

Related

How to correct VS Code terminal pointing to wrong folder C:\Windows\System32\WindowsPowerShell\v1.0?

I try to open a React project path in terminal window using VS Code's Open in Integrated Terminal (Ctrl+Shift+`), but it sets C:\Windows\System32\WindowsPowerShell\v1.0 as current directory and not the project directory.
It doesn't behave like that for other projects (folders & paths).
This happened after I moved the files to another folder on my PC.
Screen shot of VS Code context menu with menu item Open in Integrated Terminal and the TERMINAL window with Windows PowerShell output and the path set as current directory.
this is return to special characters in file name.
characters like [ , ] made this error on VS code. git bash and CMD run well with them but vs code not.im not certain this is a bug or not

Post-Build Event Fails to Run Batch File

I recently started adding Post-Build events to my projects and today I came across an annoying issue.
Post-build event command line:
"$(ProjectDir)PostBuildRelease.bat"
PostBuildRelease.bat - 1
CMD
SET parameter=%1
CD %1
The above errors with message:
'´╗┐CMD' is not recognized as an internal or external command,
operable program or batch file.
"Saved parameter "
Which is strange, because I definitely have another project where the first line reads CMD and it works perfectly.
Setting the first line to SET parameter=%1 also complains that SET is not a recognised command.
PostBuildRelease.bat - 2
Trying the same but with an empty file gives this error (build fails):
The command "C:\Users\name\ITSelfHelp\ITHelp\PostBuildRelease.bat" exited with code 1.
PostBuildRelease - 3
Entering the CMD code directly into the Post-Build Event command line field results in a successful post-build event, but this is not ideal for me and seems strange as I can run from an external .bat in other projects.
Can anyone explain this behaviour, or let me know how I can debug this?
It turns out the text editor in Visual Studio was encoding my batch script.
To recreate this:
Right-click the solution
Add file
Text file
Rename file.bat
Write the script in Visual Studio
Build
Check the output window for the error
To resolve:
Delete the file created in Visual Studio
Created a new .bat file in the same location using Windows Explorer
Open the file with Notepad++ and paste in the script
Save and build
I also noticed that syntax highlighting was not being applying in the file created by Visual Studio, which is a bit of a giveaway along with the ´╗┐ in front of the errors.

Application does not run from command prompt but runs with double click ERROR: WERC6F9.tmp.WERInternalMetadata.xml

I have a WPF application, when double click from it is location it runs - no problems.
When I trying to start the app from command prompt I get an error.
I need to run the app from command prompt (also using startup register)
Files that help describe the problem:
C:\Users\xxx\AppData\Local\Temp\WERC6F9.tmp.WERInternalMetadata.xml
C:\Users\xxx\AppData\Local\Temp\WERE6F8.tmp.appcompat.txt
C:\Users\xxx\AppData\Local\Temp\WERE718.tmp.mdmp
What could be the problem
I hope this can help you
This could be because of Path. When you Double click app the required files for the application will there at the current folder hence the application is able to find and load the files required. But if your executing it from different path other than app path, lets say
Your application is present in the location D:\Data\Example.exe.
And your executing the app from different location Say C:\Program files, now the app will start running from C:\Program files and it'll start searching required files at C:\Program files and some temp locations once it don't find there it'll throws exception
You can do like this
Write a Batch file.first change the current directory to application directory in this case say D:\Data or you can add your application path to path environment variable and use it
Then Invoke the exe
Save the this file and you call this file from where you want
I had the same issue.
I found out that it was due to me using Debug not Release while building my application. The Microsoft .dll-s in the redistributable is for release.

Getiing error message 'Failed Installing JBAS50SVC' whle running service.bat file in Windows 7

I need to run Jboss 7 as service.
Followed these steps :-
Copied my Jboss to C:\Program Files <86>
Downloaded Jboss-native-2.0.10-windows-x64-ssl and copied the contenst of bin catalog to %JBOSS_HOME%/bin
Changes done on service.bat as per link instructions
https://community.jboss.org/message/724488
Changed my dir location to my Jboss bin
and given command service.bat install
C:\Program Files \jboss7>bin>service.bat install
Failed installing JBAS50SVC
Access is Denied.
Service JBoss Application Server 7.1.1 installed.
I'm not able to rectify this problem .
It appears to be windows access issue.
Try the following:
Does the windows ID you are using have Administrator privileges? If no, get a Admin ID else if Yes, proceed to step 2.
Try to do the same but in some other drive (not c: )
UPDATE #1 : OP says he can not see the output of service.bat file
Follow the following steps
Open start menu
Search for "cmd"
Right click "cmd" and run as Administrator
type in following command
cd C:\Program Files \jboss7\bin
Type service.bat and observe the output
On a 2008 Windows Server this occurs because you're not running the command line as an administrator. Those of us who have spent considerable amounts of time on 2003 server, and others before that, keep forgetting that your logged in ADMIN level account does NOT get passed to the command line automatically like with previous versions of Windows.
With any additional errors, past this one, I would keep going back to the service.bat file and looking at the path statements, throughout that file, to ensure that they are all correct to reach what is correct for your installation.
Also, don't forget to create a log folder under standalone (unless you're doing a domain install). Failure to do that will also cause issues as well.
yoda

VS2003 Build on Command Line Throw Errors

I am trying to do an automated build using the command line for Visual Studio 2003. I have the following codes:
call "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\vsvars32.bat"
Devenv /rebuild debug /project Project1 "C:\Builds\MyApp\Sample.sln"
Devenv /rebuild debug /project Project2 "C:\Builds\MyApp\Sample.sln"
Devenv /rebuild debug /project Project3 "C:\Builds\MyApp\Sample.sln"
In my script above, I build each project individually (like I saw in a tutorial on the internet). But each time I try to build, it throws me a lot of errors about the Microsoft Namespaces not being found. Below are sample error messages I get on the build:
Namespace or type 'Data' for the Imports
'Microsoft.Practices.EnterpriseLibrary.Data' cannot be found.
Namespace or type 'Sql' for the Imports
'Microsoft.Practices.EnterpriseLibrary.Data.Sql' cannot be found.
Namespace or type 'Logging' for the Imports
'Microsoft.Practices.EnterpriseLibrary.Logging' cannot be found.
Satellite assemblies could not be built because the main project
output is missing.
I have tried another method to build but this time it's the entire solution but still it gives me the same errors.
call "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\vsvars32.bat"
Devenv C:\Builds\MyApp\Sample.sln /rebuild "Debug"
Can somebody please tell me what i'm missing?
I have over 50 projects in a single solution and it would really help me big time to create an automated build for this.
Thanks a lot! Cheers!
Don't "call" the "vsvars32.bat" file.
Use the full path for "Devenv.exe" (instead of #1).
Optionally: (maybe this is the kicker)..... cd to the directory where the .sln file resides.
"c:\myfullpath\Devenv.exe" /rebuild debug /project Project1 "C:\Builds\MyApp\Sample.sln"
Try that from the command line and see what happens.
Future Note:
In 2.0, you do NOT use "devenv.exe", you change it to msbuild.exe. (Just as an FYI).
You can also look up MSBee. (How to build 1.1 apps with msbuild).
EDIT
All of these lines are working for me.......I don't have VS2003 installed anymore. But I used VS2010 devenv.exe to run some samples.
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" MySolution.sln /clean
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" /build debug /project MyProject001 MySolution.sln
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" /rebuild debug /project MyProject001 MySolution.sln
Note, if I switch the /clean with the MySolution.sln (in the first example).....it fails. So there may be some ordering voodoo.
I'm not sure exactly what you want but to automate the compilation of my C# projects I use msbuild.
For example this is a code I use to build some XNA project games:
Sample Code:
#echo off
set path=%path%;C:\Windows\Microsoft.NET\Framework\v4.0.30319
Rem In the above line replace "v4.0.30319" with the latest framework version you have
Rem (or include the path to youy inbuilt compiler)
Msbuild "C:\Builds\MyApp\Sample.sln"
Now to meet any other requirements you want you can just type msbuild /? after you added it to your path environemtn variable. The best thing is this will be inbuilt for every windows computor!
Please ask if you want to know anything else, or if you want to do something else.
Try this:
Each of your Projects should have a reference to the "Microsoft.Practices.EnterpriseLibrary" - Files, dlls or whereever these are stored.
Maybe during an open IDE one holds a reference and copies it to the correspodending build folder. (After Build Task). While builing it independly the references could not be found.
If any copy tasks exist - Check the relative paths. Maybe your depended files targets to a different folder after build compared to build in the IDE.?
Just another idea..

Resources