Author Topic: shell_exec doesn't work  (Read 2306 times)

0 Members and 3 Guests are viewing this topic.

Offline someChanse

  • Major(1)
  • Posts: 8
shell_exec doesn't work
« on: June 12, 2012, 01:53:09 pm »
windows 7 x64. i'm trying to call shell_exec function like this:
Code: [Select]
shell_exec('C:\pg.exe');Soldat Server is ruined with -safe 0 key,but it does not run the program. What's the problem?
« Last Edit: June 12, 2012, 04:57:47 pm by someChanse »

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: shell_exec doesn't work
« Reply #1 on: June 12, 2012, 05:13:34 pm »
Are you 100% sure that program isn't getting run? Maybe open up Process Hacker/Explorer and watch the soldatserver.exe process to see if it forks a new process.  What's that pg.exe do anyway? Does it output anything? Does it sit for a while or immediately exit? You can also try changing the backslash to a forward slash.
There are other worlds than these

Offline someChanse

  • Major(1)
  • Posts: 8
Re: shell_exec doesn't work
« Reply #2 on: June 13, 2012, 01:30:35 am »
I wrote this program in С++. When I run it manually - as a result of its execution it create a out.txt file in the C catalog and immediately terminates itself. But when I try to do it with the soldat server, it's still doesn't work. And also i'm try changing the backslash to a forward slash, doensn't work too.
« Last Edit: June 13, 2012, 01:39:50 am by someChanse »

Offline Shoozza

  • Retired Soldat Developer
  • Veteran
  • ******
  • Posts: 1632
  • Soldat's Babysitter
    • Website
Re: shell_exec doesn't work
« Reply #3 on: June 13, 2012, 05:18:50 am »
I assume you have scripting enabled (in server.ini)
Which version of windows do you use?
32 or 64 bit?

Lets do a few tests.
Try this:

  WriteLn('Before shell_exec!');
  shell_exec('notepad.exe');
  WriteLn('After shell_exec!');

this should open notepad.

Another test:
shell_exec('echo test>tmp.txt');
should write into the file tmp.txt in the soldatserver folder (when you started the exe it in that folder)
Rules
Tools: ARSSE - SARS - SRB - chatMod

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: shell_exec doesn't work
« Reply #4 on: June 13, 2012, 06:37:46 am »
shell_exec('echo test>tmp.txt');
should write into the file tmp.txt in the soldatserver folder (when you started the exe it in that folder)

I didn't think windows has echo or output redirection like in unix?
There are other worlds than these

Offline someChanse

  • Major(1)
  • Posts: 8
Re: shell_exec doesn't work
« Reply #5 on: June 13, 2012, 10:00:22 am »
I assume you have scripting enabled (in server.ini)
Yes, of course.
32 or 64 bit?
Win7 x64.
Try this:
WriteLn('Before shell_exec!');
shell_exec('notepad.exe');
WriteLn('After shell_exec!');
in the server console I see messages 'Before shell_exec!' and 'After shell_exec!', but notepad is not run.
Another test:
shell_exec('echo test>tmp.txt');
The file also does not create.

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: shell_exec doesn't work
« Reply #6 on: June 13, 2012, 10:44:05 am »
shell_exec tries to execute as follows: "command.com /c <yourcommand>". I'm not entirely sure if this isn't a little bit deprecated in windows 7.
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: shell_exec doesn't work
« Reply #7 on: June 13, 2012, 03:56:53 pm »
shell_exec tries to execute as follows: "command.com /c <yourcommand>". I'm not entirely sure if this isn't a little bit deprecated in windows 7.

uh I think it might be:


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\josephg>cd \

C:\>command.com
'command.com' is not recognized as an internal or external command,
operable program or batch file.

C:\>


It should be "cmd.exe /c command" instead of using command.com, because that apparently works.
« Last Edit: June 13, 2012, 04:00:52 pm by jrgp »
There are other worlds than these

Offline Shoozza

  • Retired Soldat Developer
  • Veteran
  • ******
  • Posts: 1632
  • Soldat's Babysitter
    • Website
Re: shell_exec doesn't work
« Reply #8 on: June 14, 2012, 12:20:35 pm »
Ok on 64 bit versions COMMAND.COM is missing (it was available in 32bit versions of Windows for compatibility reasons).
Thats why it doesn't work.

I replaced command.com with cmd.exe so it will work in new versions of soldatserver.
I'm not sure if this workaround will help you but but maybe copy pasting cmd.exe in soldatservers folder and renaming it command.com will make it work.
Rules
Tools: ARSSE - SARS - SRB - chatMod

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: shell_exec doesn't work
« Reply #9 on: June 14, 2012, 12:21:28 pm »
I'm not sure if this workaround will help you but but maybe copy pasting cmd.exe in soldatservers folder and renaming it command.com will make it work.

Doesn't Windows require executables to have the relevant file extension?
There are other worlds than these

Offline someChanse

  • Major(1)
  • Posts: 8
Re: shell_exec doesn't work
« Reply #10 on: June 14, 2012, 03:27:28 pm »
I'm not sure if this workaround will help you but but maybe copy pasting cmd.exe in soldatservers folder and renaming it command.com will make it work.
It's work! For me the issue is resolved. :) Thank you to all for support!
« Last Edit: June 14, 2012, 05:35:46 pm by someChanse »

Offline Shoozza

  • Retired Soldat Developer
  • Veteran
  • ******
  • Posts: 1632
  • Soldat's Babysitter
    • Website
Re: shell_exec doesn't work
« Reply #11 on: June 14, 2012, 06:40:21 pm »
I'm not sure if this workaround will help you but but maybe copy pasting cmd.exe in soldatservers folder and renaming it command.com will make it work.

Doesn't Windows require executables to have the relevant file extension?
It does but .com files are also executables (just different ones) so i guess it's ok.
You can even make your own extensions for executables (if you copy and rename stuff in the registry).

I'm not sure if this workaround will help you but but maybe copy pasting cmd.exe in soldatservers folder and renaming it command.com will make it work.
It's work! For me the issue is resolved. :) Thank you to all for support!
No problem ;)
Rules
Tools: ARSSE - SARS - SRB - chatMod