Sign in to follow this  
Followers 0
locutus243

simple dos command

24 posts in this topic

Hi guys,

I know this is something of a Do based problem but I'm asking on here because I want to build it into my autoIT script.

I'm trying to use the _rundos() function to start a program (because its not an executable I can't use Run() ) Below you can see that part of my script:-

_RunDos("start C:\Program Files\HostExplorer.nt\user\hostex\Profile\3270\Default.HEP")

It seems that the script won't work because Dos can't understand the file extension (I assume because of the space after the C:\Program). I've tried defining my path as $file and including that but it didn't work, and also using quotations marks but that also fails (although its likely its the way I'm writing the command causing this to fail)

I was wondering if anybody could tell me the solution to this problem as it is causing a problem anytime I try and use a Dos command in my scripts.

Thanks

Mark

Share this post


Link to post
Share on other sites



Hi guys,

I know this is something of a Do based problem but I'm asking on here because I want to build it into my autoIT script.

I'm trying to use the _rundos() function to start a program (because its not an executable I can't use Run() ) Below you can see that part of my script:-

_RunDos("start C:\Program Files\HostExplorer.nt\user\hostex\Profile\3270\Default.HEP")

It seems that the script won't work because Dos can't understand the file extension (I assume because of the space after the C:\Program). I've tried defining my path as $file and including that but it didn't work, and also using quotations marks but that also fails (although its likely its the way I'm writing the command causing this to fail)

I was wondering if anybody could tell me the solution to this problem as it is causing a problem anytime I try and use a Dos command in my scripts.

Thanks

Mark

1. Experiment with single and double quotes like it says in the help file...

2. Do you already have a file association defined for the ".HEP" extension?

Share this post


Link to post
Share on other sites

Hi guys,

I know this is something of a Do based problem but I'm asking on here because I want to build it into my autoIT script.

I'm trying to use the _rundos() function to start a program (because its not an executable I can't use Run() ) Below you can see that part of my script:-

_RunDos("start C:\Program Files\HostExplorer.nt\user\hostex\Profile\3270\Default.HEP")

It seems that the script won't work because Dos can't understand the file extension (I assume because of the space after the C:\Program). I've tried defining my path as $file and including that but it didn't work, and also using quotations marks but that also fails (although its likely its the way I'm writing the command causing this to fail)

I was wondering if anybody could tell me the solution to this problem as it is causing a problem anytime I try and use a Dos command in my scripts.

Thanks

Mark

Default.hep is not an executable so DOS will not be able to run it as a program. One good way to test this in future would be to try your command line in a DOS window first. Also DOS does not like spaces and these would need to be inside quotes.


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

I've tried putting single and double quotes all over the command and nothing seems to work.

As for the file association, it works when I use the 'Run' box in windows so it should be ok. Unless I need to define a file association in AutoIT, in which case I haven't, how do I do this??

Thanks for helping

Mark

P.S. I apologise for my ignorance with both Dos, Windows and AutoIT!!!

Share this post


Link to post
Share on other sites

I've tried putting single and double quotes all over the command and nothing seems to work.

As for the file association, it works when I use the 'Run' box in windows so it should be ok. Unless I need to define a file association in AutoIT, in which case I haven't, how do I do this??

Thanks for helping

Mark

P.S. I apologise for my ignorance with both Dos, Windows and AutoIT!!!

Using the Run box in windows is not the same as running a program at a DOS command prompt.


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Ahh, that I didn't know.

Well surely there is somebody on here that will have launched a program using the _rundos function. Is there anyone that can suggest how to refine the function below:-

_RunDos("start C:\Program Files\HostExplorer.nt\user\hostex\Profile\3270\Default.HEP")

Thanks for your time

Mark

Share this post


Link to post
Share on other sites

Ahh, that I didn't know.

Well surely there is somebody on here that will have launched a program using the _rundos function. Is there anyone that can suggest how to refine the function below:-

_RunDos("start C:\Program Files\HostExplorer.nt\user\hostex\Profile\3270\Default.HEP")

Thanks for your time

Mark

This does not use _rundos but it will work

Send("#r")
Send("C:\Program Files\HostExplorer.nt\user\hostex\Profile\3270\Default.HEP")
Send("{Enter}")

And will no doubt provoke better answers.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Starting the windows dialog box directly. Genius idea (and so simple), much appreciated BigDod. Thankyou for your help

Mark

Share this post


Link to post
Share on other sites

u might want to look here

http://www.autoitscript.com/forum/index.ph...ndpost&p=115180

i used the function FileGetShortName to solve the problem


The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Share this post


Link to post
Share on other sites

Starting the windows dialog box directly. Genius idea (and so simple), much appreciated BigDod. Thankyou for your help

Mark

Here is another attempt

Run(@comspec & ' /c "C:\Program Files\HostExplorer.nt\user\hostex\Profile\3270\Default.HEP"','',@sw_hide)


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

@BigDod

thats how _RunDos does it :o

B)


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

its on the top FAQ list

6. Why can I only use Run() to execute .exe files? What about .msi / .txt and others?

Only a few file extensions are usually "runable" - these are .exe, .bat, .com, .pif. Other file types like .txt and .msi are actually executed with another program. When you double click on a "myfile.msi" file what actually happens in the background is that "msiexec.exe myfile.msi" is executed. So to run a .msi file from AutoIt you would do:

RunWait("msiexec myfile.msi")

Or, an even simpler way is to run the command "start" which will automatically work out how to execute the file for you:

RunWait(@COMSPEC & " /c Start myfile.msi")

thus... maybe this will do the trick

RunWait(@COMSPEC & " /c Start Default.HEP")

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Hey guys, thanx for all the advice. Looks like wiv all the ideas you've given me that i should have no problem in the future!!

Much appreciated

Mark

Share this post


Link to post
Share on other sites

Hi,

I am not surprised how much trouble there is "getting the quotes right"

I have settled my problem by always using this type of structure to keep the quotes honest;

If StringInStr($File, " ") Then $File = '"' & $File & '"'

If StringInStr($AnswerFile, " ") Then $AnswerFile = '"' & $AnswerFile & '"'

$Command = @ComSpec & " /c " & 'FINDSTR '& $Switches &' '& $File &'>'&$AnswerFile

$DosFINDSTRReturn=RunWait($Command, @SystemDir, @SW_HIDE)

If you really look at "double quotes", they sometimes need to be triple etc.

i would be interested to hear if this solves the problems people have with the quotes, or if you really believe there is some other problem?

Best, randall

Share this post


Link to post
Share on other sites

more examples

$rc = _RunDos("for /f %%s in ('dir /b *.dll') do regsvr32 /s %s")

or

$ErrorCode = RunWait( 'Psservice \\' & $line & ' stop "Windows Firewall/Internet Connection Sharing (ICS)"',"",@SW_HIDE)

Share this post


Link to post
Share on other sites

Hi guys,

I know this is something of a Do based problem but I'm asking on here because I want to build it into my autoIT script.

I'm trying to use the _rundos() function to start a program (because its not an executable I can't use Run() ) Below you can see that part of my script:-

_RunDos("start C:\Program Files\HostExplorer.nt\user\hostex\Profile\3270\Default.HEP")

It seems that the script won't work because Dos can't understand the file extension (I assume because of the space after the C:\Program). I've tried defining my path as $file and including that but it didn't work, and also using quotations marks but that also fails (although its likely its the way I'm writing the command causing this to fail)

I was wondering if anybody could tell me the solution to this problem as it is causing a problem anytime I try and use a Dos command in my scripts.

Thanks

Mark

If I am not mistaken this slight modification should make it work.

_RunDos('start "C:\Program Files\HostExplorer.nt\user\hostex\Profile\3270\Default.HEP"')

The thing to remember is that if there are spaces in the path then you need quotes around the path. or you could use

$a = FileGetShortName("C:\Program Files\HostExplorer.nt\user\hostex\Profile\3270\Default.HEP")
_RunDos("start " & $a)

FileGetShortName removes all spaces from the path.

Share this post


Link to post
Share on other sites

Hi,

@hankjrfan; I think the short names are giving people grief (see other thread)?

more examples

CODE

$rc = _RunDos("for /f %%s in ('dir /b *.dll') do regsvr32 /s %s")

or

CODE

$ErrorCode = RunWait( 'Psservice \\' & $line & ' stop "Windows Firewall/Internet Connection Sharing (ICS)"',"",@SW_HIDE)

Are these problemones or working ones?

I agree with te extra " ' " comment, and it is not clear if some people are using double quotes[""] instead of triple ['"'] , which may look the same on the screen (the second is [' " '] without spaces); hence why I suggest not trying to do it all one one line; use :stringreplace " only if needed for spaces

Best, Randall

Share this post


Link to post
Share on other sites

Personally if I need to work with a command line with file and quotes all over the place, I do it this way:

Local $File1 = 'C:\A.EXE'
Local $File2 = 'C:\B.TXT'
Local $File3 = 'C:\Program Files\Filename with Spaces.txt'

Local $Cmd = StringFormat('%s /c "%s" /switch "%s" > "%s"', @ComSpec, $File1, $File2, $File3)
RunWait($Cmd)

Share this post


Link to post
Share on other sites

I am not surprised how much trouble there is "getting the quotes right"

Try to create an Autoit script form Autoit and you will find out what fun is, hehe. B)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0