Page 1 of 2
running an exe on batch...
Posted: 05 Oct 2015 07:06
by TheHunterManX
I am having problems with my file. I want to make a server using ftp and I put all my data in the Cred.bat file, then converted it to an exe. However, when I run it using batch, It does nothing. I also do not want a temp file as it can be accessed if someone clicks it as it is being ran. Does someone know how to do this?
Example.exe content:
set p1=1
set p2=2
set p3=7
Example.bat content:
call Example.exe
echo %p1%
echo %p2%
echo %p3%
pause
what should happen on cmd:
1
2
7
press any key to continue...
What happens:
Echo is off
Echo is off
Echo is off
press any key to continue...
Please dont say use a temp file.
Re: running an exe on batch...
Posted: 07 Oct 2015 15:32
by trebor68
Your first file is running as following file:
Code: Select all
@echo off
setlocal
set p1=1
set p2=2
set p3=7
endlocal
Within around some variables are set. These variables are set in the converted file, but there is no output.
The following file
File1.cmd an output that can be used in the other batch file continues to take place.
This file can converting to
File1.exe.
Code: Select all
@echo off
setlocal
set p1=1
set p2=2
set p3=7
echo %p1% %p2% %p3%
endlocal
Here is
File2.cmd:
Code: Select all
@echo off
setlocal ENABLEEXTENSIONS
for /f "tokens=1-3" %%a in ('file1') do (
set p1=%%a
set p2=%%b
set p3=%%c
)
echo value p1: %p1%
echo value p2: %p2%
echo value p3: %p3%
endlocal
pause
This is just a simple solution to this problem. Depending on the output of the data from File1.exe (converted file File1.cmd) is also the input of data in File2.cmd adapt.
Re: running an exe on batch...
Posted: 08 Oct 2015 04:58
by foxidrive
TheHunterManX wrote:I put all my data in the Cred.bat file, then converted it to an exe.
I also do not want a temp file as it can be accessed if someone clicks it as it is being ran.
Compiled batch files work by creating the actual temporary batch script on the hard drive to run it.
and it can be accessed by anyone with the knowledge to locate it.
Re: running an exe on batch...
Posted: 08 Oct 2015 06:57
by TheHunterManX
Thanks trebor68for posting a solution! I will test it out in a bit...
Re: running an exe on batch...
Posted: 09 Oct 2015 05:09
by TheHunterManX
Sorry, but it didnt work,when i have the files alone they work(File1.cmd
File2.cmd), but when I compile the .cmd into a .exe, delete File1.cmd, and run File2.cmd, it doesnt work(File1.exe, File2.cmd). Please try another solution
Re: running an exe on batch...
Posted: 10 Oct 2015 03:12
by penpen
Could it be, that you are using an option "invisible" (or similar) when you are "compiling" the batch to an executable using something like
http://www.f2ko.de/en/ob2e.php?
If it is true notice that in such a case the file1.exe process opens an own hidden console window to execute the local copy of file1.cmd, including:
- host for console window
- windows command processor
- file1.exe
(You may use the task manager to see these processes/tasks.)
If they include any user input they might run forever, so you have to close the exe and the (hidden) windows command processor manually (in this order) - the host closes automatically.
(So better avoid such options.)
If you need to use this option, you probably have to use temporary files, for example:
- redirect the output of the echo in "file1.cmd" to "p123.txt"
- change the data source of "for /f" to the tmporary file
- delete the temporary file
penpen
Edit: Section 2: Corrected a faulty description by replacing:
"that the file1.exe process is opened in its own hidden console window" with
"that in such a case the file1.exe process opens an own hidden console window to execute the local copy of file1.cmd".
Re: running an exe on batch...
Posted: 10 Oct 2015 08:02
by Aacini
When an .exe file is executed, the system creates a new
local copy of the environment for it, so any change made in this environment is lost when the .exe ends. There is no way to return a value from an .exe program to its parent cmd.exe environment, don't matters if the .exe was created compiling a source .bat file.
I am pretty sure that
previous trebor68's solution should work. Create this
File1.bat:
Compile it and execute this command:
After that, the
output.txt file should contain this line:
If not, then the problem is related to
the compiler itself. If the text file does contain previous line, then trebor68's solution should work.
We need more details on the problem, because "it doesnt work" don't helps...
Antonio
Re: running an exe on batch...
Posted: 10 Oct 2015 12:38
by TheHunterManX
So since i cannot just say it doesnt work, I will upload a video shortly...
Re: running an exe on batch...
Posted: 10 Oct 2015 12:43
by Squashman
TheHunterManX wrote:So since i cannot just say it doesnt work, I will upload a video shortly...
Not really necessary.
What you could do is provide a lot more detail. Like what bat to exe compiler you are using. What Windows Operating System you are using. The EXACT code you are using(NO OBFUSCATED CODE)!
Re: running an exe on batch...
Posted: 10 Oct 2015 13:40
by trebor68
Try again my first file without the commands "SETLOCAL" and "ENDLOCAL". See also the message from Aacini.
The output of the three values in file File1.cmd carried out in a single line. The reading is also of three individual values, each consisting of a single value with no spaces or commas.
Before you work with complex values want to try once to test with simple values.
Re: running an exe on batch...
Posted: 10 Oct 2015 13:53
by TheHunterManX
I know to work with simple first for testing...
So the file1.cmd and file2.cmd worked, however, when i compiled file1.cmd and executed file2.cmd again it did not give values. I have turned off setlocal and used it.
Operating system (it does not matter however i will still reveal it):
Windows xp sp3
Compiling:
Bat2exe.exe (offline program)
Other info: When i run file1.exe alone it runs cmd saying the numbers but it doesnt when i run file2.cmd. This does work if file1.cmd in not compiled.
Re: running an exe on batch...
Posted: 10 Oct 2015 13:59
by Squashman
TheHunterManX wrote:Bat2exe.exe (offline program)
What website did you get it from?
What parameters did you compile it with?
Re: running an exe on batch...
Posted: 10 Oct 2015 14:05
by TheHunterManX
this one:
http://www.f2ko.de/en/b2e.phpbut i use 1.4 instead because it is easier.
Also there is only input file, icon, paste, and output file.
Re: running an exe on batch...
Posted: 10 Oct 2015 14:43
by Aacini
TheHunterManX wrote:
Other info: When i run file1.exe alone it runs cmd saying the numbers but it doesnt when i run file2.cmd. This does work if file1.cmd in not compiled.
How do you know that file1.exe "runs cmd"? If you run file1.exe alone the output must be
just one line with the three numbers only: "1 2 7".
Please, do the following: execute this line
Then, post here the contents of output.txt file. Please, use code tags to enclose the file contents: enter left square-braquet, "code" without the quotes and right square-braquet in a line; then the contents of the file and after it: left square-braquet, "/code" without the quotes, and right square-braquet.
Antonio
Re: running an exe on batch...
Posted: 10 Oct 2015 14:48
by TheHunterManX
So here is the output...
[code][/code]
Nothing! when i run the file1.exe it runs cmd(command prompt to be exact) and closes a half second later and i see the numbers for a split second.