I am writing code to download an app from server in visual studio 2005(VC++). After downloading it when I start running it line 3 does not run the exe file while if I write it as
system("c:/pg/ap/app.exe")
it starts running.
Can anybody tell me why this is happening?
1.const char * str;
2. HRESULT hr = URLDownloadToFile ( NULL, _T("file_path/app.exe"),(LPCWSTR)str,0,NULL);
3. system(str);
Rather then using System() function, try ShellExecute(), it ll solve your problem.
For more help refer this
Related
I am getting error when calling OS command for Peoplecode using EXEC function.
The call is like this
CommitWork();
&ShellCommand = "/path/mytest.sh param1 param2";
&ReturnCode = Exec(&ShellCommand, %Exec_Synchronous + %FilePath_Absolute);
The &ShellCommand is built using the path, executable and parameters
to be passed as shown above. That command works fine when executed
independently.
I keep getting error 255. Is there anything about the syntax? Does anybody have a tested or working example or any suggestion?
Thank you guys for responding. The command was running fine from shell scripts but not from Peoplesoft. It turned out that the current folder on the application server was not correct. So I added a CD command as the first line in the shell script to change current folder to the correct folder. That worked.
Thanks again.
the syntax looks correct.
I use similar code to call bat files.
Exec("C:\windows\system32\cmd.exe /c C:\Test\mybat.bat param1 param2", %Exec_Synchronous+%FilePath_Absolute);
Have you tried with an absolute path instead of a relative path?
error code 255 seems to be an out of range error code.
see http://tldp.org/LDP/abs/html/exitcodes.html
I would check the assumptions that you're making.
Is the same username running the shell script, your username vs the app server username?
Is the environment set up the same way for the app server username vs your username?
file permissions
I try to compile project using PowerShell command.
Problem is that there is a lot of arguments (75000 characters)
When I try to run compilation I got error:
This command cannot be run due to the error: The filename or extension is too long.
I have also changed value in registry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled but it didn’t helped.
I am using Windows 10 Pro.
Do you know where can be problem?
Just in case this grabs anyone else. I received this error but the real problem was my StartInfo.Arguments value was too big. It had nothing to do with the filename I was specifying.
I have written a AutoHotkey script that works well uncompiled, but no matter which Base File (.bin) I use to compile the exe in Ahk2Exe, it fails for some unknown reason. Here's the AHK script:
SetTitleMatchMode, 2
WinGet, PID, PID, Anime Studio ahk_class LM_Wnd
Process, Close, %PID%
if 1 && (%ErrorLevel% != 0)
{
Run, %1%
}
And here's how I'm running it, from a Lua script (double-quotes are for spaces in actual paths):
--to uncompiled AHK (working code)
os.execute("C:/Users/JWesley/Desktop/AutoHotkey/AutoHotkeyU64.exe ".."\"".."C:/Users/JWesley/Files/AS/Anime Studio Pro/scripts/utility/ReopenAS.ahk".."\"".." "..path)
--to compiled AHK (not working)
os.execute("\"".."C:/Users/JWesley/Files/AS/Anime Studio Pro/scripts/utility/ReopenAS64.exe".."\"".." "..path)
I'm passing the variable "path" from Lua to the AHK script (%1%). I've tried setting the AHK compiled exe to Run As Administrator, but that didn't help.
path = "C:/Users/JWesley/Desktop/test.anime"
I've tried using os.execute('pause') so that I have a chance to read any command prompt messages, but the first one still closes before the paused one opens.
EDIT: Okay, I got this to leave the prompt open:
os.execute("cmd.exe /k"..'"C:\\Users\\JWesley\\Desktop\\AutoHotkey\\AutoHotkeyU64.exe" "C:\\Users\\JWesley\\Files\\AS\\Anime Studio Pro\\scripts\\utility\\ReopenAS.ahk" "' .. path .. '"')
And got this message in the prompt:
The filename, directory name, or volume label syntax is incorrect.
I found a solution here: os.execute with filename and argument containing spaces Turns out it was more a Lua problem than AutoHotkey, although I'm still unsure why the difference between compiled and uncompiled AHK script. In Lua, I checked if the path had any spaces, and if so:
path = "\""..path.."\""
Then I did:
com = "\"".."type NUL && ".."\"".."C:/Users/JWesley/Files/AS/Anime Studio Pro/scripts/utility/ReopenAS64.exe".."\"".." "..path.."\""
os.execute(com)
Supposedly this keeps the command line from removing the outer quotes, which are necessary with spaces in the path.
Now my only problem is the compiled script running slow due to my anti-virus, but that's a separate issue.
Thanks for the feedback.
I want to Launch and .exe file from an m-file in MATLAB. The .exe does not Launch when i try. In restPath, the path of the .exe included. I am coding in a Windows Environment using the command line. My idea was to pass the command to run the .exe to the command line.
command = restPath;
[status,cmdout] = system(command,'-echo');
The error message is; Error file .cfg not found...
Do you have any suggestions?
Best regards
Edit: The .exe is now launched in 2 iterations. 1. cd to file, 2. Launch
addpath(restPath);
command = horzcat('cd ',restPath);
[status,cmdout] = dos(command,'-echo');
execute = 'abc.exe';
[statusExe,cmdoutExe] = system(execute,'-echo');
The main issue that I see here is that you are using two separate commands for the cd and the execution. Once the cd command executes, the command line context is thrown away and you start with a new one when you execute the system command (so the cd has no effect).
I would suggest either concatenating the two commands into one using the '&' notation like the following:
[status,cmdout] = dos([command ' & ' execute],'-echo');
or you could change your Matlab workspace first using a standard cd command in your mscript and then execute the system command.
currentPath = pwd;
cd(restPath);
execute = 'abc.exe';
[statusExe,cmdoutExe] = system(execute,'-echo');
cd(currentPath);
It is also possible that the exe you are calling is expecting an additional input to point to the .cfg file (although this may not be an issue if you have that in the same directory as the exe and it expects it to be there).
I need to create a .exe file that opens an .html document with the default browser.
In command prompt, start myfile.html works, but I don't know how to turn that into an .exe file.
How can I do that please?
Thank you.
Quite useless IMHO... Anyway use a .BAT file instead and use some app around there that converts .BAT to .EXE.
Why not just use a .bat file? Much less hassle than compiling an .exe. As well, in Windows, double-clicking the .html file would open it in the default browser anyways, so you're not gaining much.
I'd echo the questions about why you'd want to do this, but if you really insist on doing it, it shouldn't be terribly difficult.
#include <windows.h>
int main(int argc, char **argv) {
if (argc !=2) {
MessageBox(NULL, "Usage: exec_html <html_file>", "Usage Error", MB_OK);
return 1;
}
if ((int)ShellExecute(NULL, "open", argv[1], NULL, NULL, SW_SHOWNORMAL) < 32) {
MessageBox(NULL, argv[1], "Could not open file", MB_OK);
return 1;
}
return 0;
}
Compile with a C or C++ compiler of your choice. If (as sounds like the case) you don't normally use either, the easiest way to go is probably get Microsoft Visual C++ Express, a free (as in beer) download.
First download a bat to exe converter here, then open notepad and type the following:
#echo off
start myfile.html
exit
Save it as whatever you want (.bat) and then start bat to exe converter and select the batch file and click the compile button.
This way works and too everyone wondering why you might want to do this, I infact have been looking everywhere for this and am glad I found it. I needed to make a ZIP file and inside I needed my game to be runable through an exe file and my game could only be run through HTML so I found this and have been able to do so. :)
You can use ShellExecute with "open" as verb from C or C++.
First download bat to exe converter from the following link:
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html
Then open notepad and type the following:
#echo off
start myfile.html
exit
Save it as whatever you want.bat and then start bat to exe converter and select the batch file and click the compile button.
Now you get the exe file you wanted.