Sign in to follow this  
Followers 0
Eviltim

@comspec

24 posts in this topic

is it possible to execute more than 1 command using @ComSpec?

like using "cd" to change to a directory then execute a program.

Run(@ComSpec & " /c " & 'cd C:\Program Files\Media Player Classic\', "", @SW_HIDE)

Run(@ComSpec & " /c " & 'mplayerc.exe ', "", @SW_HIDE)

this doesnt seem to do the job for me.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

is it possible to execute more than 1 command using @ComSpec?

Yes, try this:

Run(@ComSpec & " /c " & 'cd C:\Program Files\Media Player Classic\ && mplayerc.exe', "", @SW_HIDE)

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

is it possible to execute more than 1 command using @ComSpec?

like using "cd" to change to a directory then execute a program.

Run(@ComSpec & " /c " & 'cd C:\Program Files\Media Player Classic\', "", @SW_HIDE)

Run(@ComSpec & " /c " & 'mplayerc.exe ', "", @SW_HIDE)

this doesnt seem to do the job for me.

<{POST_SNAPBACK}>

because you can specify the running directory in the Run() function, i'm not sure why you'd need to do a "cd" or even use @comspec for that matter... try this..
Run("C:\Program Files\Media Player Classic\mplayerc.exe","C:\Program Files\Media Player Classic\",@SW_hide)

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Yes, try this:

Run(@ComSpec & " /c " & 'cd C:\Program Files\Media Player Classic\ && mplayerc.exe', "", @SW_HIDE)

Cheers

Kurt

<{POST_SNAPBACK}>

That line didnt work, i put 2 PAUSE commands and took out @SW_HIDE to see if both commands where executed and only 1 PAUSE came up. im not sure what && is suppose to do, maybe a carriage return?

because you can specify the running directory in the Run() function, i'm not sure why you'd need to do a "cd" or even use @comspec for that matter... try this..

Run("C:\Program Files\Media Player Classic\mplayerc.exe","C:\Program Files\Media Player Classic\",@SW_hide)

<{POST_SNAPBACK}>

sorry, i forgot to say that im trying to open a file with this program.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

That line didnt work, i put 2 PAUSE commands and took out @SW_HIDE to see if both commands where executed and only 1 PAUSE came up.  im not sure what && is suppose to do, maybe a carriage return?

&& tells cmd.exe to execute the two commands one after another, BUT only if the first command succeeds (returns an exitvalue of 0)!! If you want to execute both commands, regardless of any errors, use just one ampersand.

It works for me with this test.

Run(@ComSpec & " /c " & 'cd C:\temp && dir > dir.txt', "", @SW_HIDE).

Try your concatenated commands in a dos box and see what happens. It works in general, so I guess there is a problem with your code.

EDIT: I'm not sure if this works on Win98. It should work on Win >= Win2K. Tested it with Win2k.

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

&& tells cmd.exe to execute the two commands one after another, BUT only if the first command succeeds (returns an exitvalue of 0)!! If you want to execute both commands, regardless of any errors, use just one ampersand.

It works for me with this test.

Run(@ComSpec & " /c " & 'cd C:\temp && dir > dir.txt', "", @SW_HIDE).

Try your concatenated commands in a dos box and see what happens. It works in general, so I guess there is a problem with your code.

EDIT: I'm not sure if this works on Win98. It should work on Win >= Win2K. Tested it with Win2k.

Cheers

Kurt

<{POST_SNAPBACK}>

works fine in a dos box.

i tried your example up above and it put the dir.txt in the folder i had the script in, not the temp folder. it seems to be having trouble with the cd command. maybe i should replace "cd" with "PATH="

oh b.t.w im using xp sp2

EDIT: i also tried

Run(@ComSpec & " /c " & 'cd C:\temp && dir > C:\temp\dir.txt', "", @SW_HIDE)
but the list is generated from the script directory then saved to C:\temp Edited by Eviltim

Share this post


Link to post
Share on other sites

Looks to me like the problem is the spaces in your path, you need to surround it in quotation marks, otherwise it thinks you're handing it a bunch of seperate parameters.

Run(@ComSpec & " /c " & 'cd "C:\Program Files\Media Player Classic\" && mplayerc.exe', "", @SW_HIDE)

A similar example on my machine worked fine.

Share this post


Link to post
Share on other sites

works fine in a dos box.

i tried your example up above and it put the dir.txt in the folder i had the script in, not the temp folder. it seems to be having trouble with the cd command.

...

EDIT: i also tried

Run(@ComSpec & " /c " & 'cd C:\temp && dir > C:\temp\dir.txt', "", @SW_HIDE)
but the list is generated from the script directory then saved to C:\temp
I'm sorry, I have no further idea. It works on my system as it should...

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

If you're coding for multiple computers then this isn't the way to go because Windows 98 doesn't support the & operator. I would suggest writing to a temporary batch file, calling that via RunWait() and then deleting it.

Share this post


Link to post
Share on other sites

...sorry, i forgot to say that im trying to open a file with this program.

<{POST_SNAPBACK}>

Can you just "run" the file to be opened and let the file associations pick the app?

Run(@ComSpec & " /c C:\Temp\sample.txt", "", @SW_HIDE)

or

Run(@ComSpec & " /c start C:\Temp\sample.txt", "", @SW_HIDE)

Using start gives several more options... see start /? from a cmd window.

If the "file association" method will not open the file of interest in the app that you want, then how about passing the file to the app on the cmd line?

Run(@ComSpec & " /c C:\WINDOWS\NOTEPAD.EXE C:\Temp\sample.txt", "", @SW_HIDE)

...or perhaps I do not understand what you are attempting...


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

This is kind of an old post but i figured out my problem.

Run(@ComSpec & " /c " & 'cd "C:\Program Files\Media Player Classic\" && mplayerc.exe', "", @SW_HIDE)
This only works if the script is in the C drive.

The whole time i was working on the D drive and im trying to get this to work on any drive.

Is this a bug or something or is there a way to get around this?

Share this post


Link to post
Share on other sites

This is kind of an old post but i figured out my problem.

Run(@ComSpec & " /c " & 'cd "C:\Program Files\Media Player Classic\" && mplayerc.exe', "", @SW_HIDE)
This only works if the script is in the C drive.

The whole time i was working on the D drive and im trying to get this to work on any drive.

Is this a bug or something or is there a way to get around this?

<{POST_SNAPBACK}>

question, is your D drive a programatically mapped drive, or a physical drive? i only ask because i've had problems before writing to a mapped drive even when i could write direction to the path without mapping...

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

question, is your D drive a programatically mapped drive, or a physical drive? i only ask because i've had problems before writing to a mapped drive even when i could write direction to the path without mapping...

<{POST_SNAPBACK}>

its an actual physical drive.

i might take what LxP said and just use autoit to make a batch file and delete it afterwards.

anyone else tried this out with a physical drive?

Share this post


Link to post
Share on other sites

its an actual physical drive.

i might take what LxP said and just use autoit to make a batch file and delete it afterwards.

anyone else tried this out with a physical drive?

<{POST_SNAPBACK}>

i'll try it at home, i have physical hd's for c and d there, but stuck at work another 2 hours... (but who's counting)

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

This is kind of an old post but i figured out my problem.

Run(@ComSpec & " /c " & 'cd "C:\Program Files\Media Player Classic\" && mplayerc.exe', "", @SW_HIDE)
This only works if the script is in the C drive.

The whole time i was working on the D drive and im trying to get this to work on any drive.

Is this a bug or something or is there a way to get around this?

<{POST_SNAPBACK}>

No bug. Check Help for the CD command. When also changing the drive, you have to use the /D switch.

CHDIR [/D][drive:][path]

CHDIR [..]

CD [/D] [drive:][path]

CD [..]

  ..  Specifies that you want to change to the parent directory.

Type CD drive: to display the current directory in the specified drive.

Type CD without parameters to display the current drive and directory.

Use the /D switch to change current drive in addition to changing current

directory for a drive.

So, do the following. I tested running the script from d-drive and it started mplayer on c-drive.

Run(@ComSpec & " /c " & 'cd /d "C:\Program Files\Media Player Classic\" && mplayerc.exe', "", @SW_HIDE)

Phillip

Share this post


Link to post
Share on other sites

No bug.  Check Help for the CD command.  When also changing the drive, you have to use the /D switch.

So, do the following.  I tested running the script from d-drive and it started mplayer on c-drive.

Run(@ComSpec & " /c " & 'cd /d "C:\Program Files\Media Player Classic\" && mplayerc.exe', "", @SW_HIDE)

<{POST_SNAPBACK}>

Many Thanks to everyone who helped me out here.

phillip123adams has solved my problems. :whistle:

ill start taking a better look at the dos commands before i jump to conclusions now but hey, you learn something new everyday, right?

Thanks Again.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Run(@ComSpec & " /c " & 'cd "C:\Program Files\Media Player Classic\" && mplayerc.exe', "", @SW_HIDE)
This only works if the script is in the C drive.

The whole time i was working on the D drive and im trying to get this to work on any drive.

Is this a bug or something or is there a way to get around this?

As mentioned you can use CD /D but that won't work on Win9x systems. Another approach is to do this:

run(@comSpec & "/c mplayerc.exe", "C:\Program Files\Media Player Classic", @SW_HIDE)

This will always work regardless of drive -- setting the working directory is equivalent to a CD command when launching a command interpreter.

Why stop there though? Can someone explain to me why we're using AutoIt to run a command interpreter to run Media Player Classic when AutoIt is inherently just fine at running things itself? --

run("C:\Program Files\Media Player Classic\mplayerc.exe", "C:\Program Files\Media Player Classic")
Edited by LxP

Share this post


Link to post
Share on other sites

As mentioned you can use CD /D but that won't work on Win9x systems. Another approach is to do this:

run(@comSpec & "/c mplayerc.exe", "C:\Program Files\Media Player Classic", @SW_HIDE)

This will always work regardless of drive -- setting the working directory is equivalent to a CD command when launching a command interpreter.

Why stop there though? Can someone explain to me why we're using AutoIt to run a command interpreter to run Media Player Classic when AutoIt is inherently just fine at running things itself? --

run("C:\Program Files\Media Player Classic\mplayerc.exe", "C:\Program Files\Media Player Classic")

<{POST_SNAPBACK}>

i suppose i should just post the whole script just to clarify things.. well here goes.

Dim $var, $label, $getlabel, $drive, $dir, $path, $test, $mac, $folder, $final, $list

$mac = '\Macromedia\Flash Player\#SharedObjects\'
$list = '"  /b > "' & @AppDataDir & $mac & 'list.txt"'

Run(@ComSpec & " /c " & 'dir "' & @AppDataDir & $mac & $list, "", @SW_HIDE)

$folder = FileReadLine(@AppDataDir & $mac & "list.txt", 1) & "\"
$final = @AppDataDir & $mac & $folder

local $temp, $i
local $output = ""

for $i = 2 to 20
    $temp = fileReadLine($final & 'localhost\Start.exe\list.sol', $i)
    $temp = stringLeft($temp, 10)
    $temp = stringStripWS($temp, 8)
    $output = $output & $temp
next

$var = DriveGetDrive( "all" )
$label = "Test_CD"
For $i = 1 to $var[0]
$getlabel = DriveGetLabel($var[$i])
If $label = $getlabel Then
    FileChangeDir ($var[$i] & "\")
    $drive = @WorkingDir
    EndIf
Next        

Select
    Case FileFindFirstFile($drive & "Test_1-4\" & $output) = "0"
        $path = "Test_1-4\"
        
    Case FileFindFirstFile($drive & "Test_5-8\" & $output) = "0"
        $path = "Test_5-8\"
        
    Case FileFindFirstFile($drive & "Test_9-12\" & $output) = "0"
        $path = "Test_9-12\"
        
    Case FileFindFirstFile($drive & "Test_13-16\" & $output) = "0"
        $path = "Test_13-16\"
        
    Case FileFindFirstFile($drive & "Test_17-20\" & $output) = "0"
        $path = "Test_17-20\"
        
    Case FileFindFirstFile($drive & "Test_21-24\" & $output) = "0"
        $path = "Test_21-24\"
        
EndSelect

$drive = '"' & $drive 
$output = $output & '"'

Run(@ComSpec & " /c " & 'cd /d "C:\Program Files\Media Player Classic\" && mplayerc.exe ' & $drive & $path & $output, "", @SW_HIDE)

This program is executed in flash, what it does is it pulls info from a file that flash has generated and uses it to execute the correct video file.

On flash, i just click a button and it generates or rewrites the list.sol file and then executes this script.This method is a far better way then just making seperate scripts for individual video files.

As far as i know, i cant use autoit to open mplayerc with a video file and the default player is not always mplayerc.

Im not sure i plan on using this on other systems but it can done by making autoit create a batch file and have that batch file delete itself.

If something doesnt look right or it can be written in a better way, please let me know.

Share this post


Link to post
Share on other sites

i suppose i should just post the whole script just to clarify things.. well here goes.

Dim $var, $label, $getlabel, $drive, $dir, $path, $test, $mac, $folder, $final, $list

$mac = '\Macromedia\Flash Player\#SharedObjects\'
$list = '"  /b > "' & @AppDataDir & $mac & 'list.txt"'

Run(@ComSpec & " /c " & 'dir "' & @AppDataDir & $mac & $list, "", @SW_HIDE)

$folder = FileReadLine(@AppDataDir & $mac & "list.txt", 1) & "\"
$final = @AppDataDir & $mac & $folder

local $temp, $i
local $output = ""

for $i = 2 to 20
    $temp = fileReadLine($final & 'localhost\Start.exe\list.sol', $i)
    $temp = stringLeft($temp, 10)
    $temp = stringStripWS($temp, 8)
    $output = $output & $temp
next

$var = DriveGetDrive( "all" )
$label = "Test_CD"
For $i = 1 to $var[0]
$getlabel = DriveGetLabel($var[$i])
If $label = $getlabel Then
    FileChangeDir ($var[$i] & "\")
    $drive = @WorkingDir
    EndIf
Next        

Select
    Case FileFindFirstFile($drive & "Test_1-4\" & $output) = "0"
        $path = "Test_1-4\"
        
    Case FileFindFirstFile($drive & "Test_5-8\" & $output) = "0"
        $path = "Test_5-8\"
        
    Case FileFindFirstFile($drive & "Test_9-12\" & $output) = "0"
        $path = "Test_9-12\"
        
    Case FileFindFirstFile($drive & "Test_13-16\" & $output) = "0"
        $path = "Test_13-16\"
        
    Case FileFindFirstFile($drive & "Test_17-20\" & $output) = "0"
        $path = "Test_17-20\"
        
    Case FileFindFirstFile($drive & "Test_21-24\" & $output) = "0"
        $path = "Test_21-24\"
        
EndSelect

$drive = '"' & $drive 
$output = $output & '"'

Run(@ComSpec & " /c " & 'cd /d "C:\Program Files\Media Player Classic\" && mplayerc.exe ' & $drive & $path & $output, "", @SW_HIDE)

This program is executed in flash, what it does is it pulls info from a file that flash has generated and uses it to execute the correct video file.

On flash, i just click a button and it generates or rewrites the list.sol file and then executes this script.This method is a far better way then just making seperate scripts for individual video files.

As far as i know, i cant use autoit to open mplayerc with a video file and the default player is not always mplayerc.

Im not sure i plan on using this on other systems but it can done by making autoit create a batch file and have that batch file delete itself.

If something doesnt look right or it can be written in a better way, please let me know.

<{POST_SNAPBACK}>

couldn't you add the name of the media file to be opened at the end of the run statement to open the specific file? like...

Run("C:\Program Files\Media Player Classic\mplayerc.exe TheMovie.avi","C:\Program Files\Media Player Classic\")
and for the record i'd just like to point out that i suggested using run command with directory way back in my first reply on this topic....

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

couldn't you add the name of the media file to be opened at the end of the run statement to open the specific file?  like...

Run("C:\Program Files\Media Player Classic\mplayerc.exe TheMovie.avi","C:\Program Files\Media Player Classic\")
and for the record i'd just like to point out that i suggested using run command with directory way back in my first reply on this topic....

<{POST_SNAPBACK}>

oh wow... that worked too :dance:

sorry sorry sorry sorry sorry sorry :whistle:

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