Sign in to follow this  
Followers 0
Ciege

Problem using XCOPY from a CMD file [SOLVED]

11 posts in this topic

#1 ·  Posted (edited)

Hi all, new to the forum. Been using autoIt for years.

Anyway I am in the process of automating a build system here. Small steps though. First put the AutoIt gui in place to call all the CMDs then convert CMDs to AutoIt.

I have an issue that when I run a CMD from AutoIt that has an XCOPY in it, it will not work. If I change the XCOPY to COPY it works fine. However, since I cannot muck with all the CMDs I have yet that is not an option at this point in time.

Here is a quick example showing that XCOPY does not work.

AutoIT script:

$foo = Run(@ComSpec & " /c C:\foo.cmd", "C:\", "",$STDERR_CHILD + $STDOUT_CHILD)

foo.cmd code:

xcopy.exe "c:\temp\*.au3" "c:\*.au3"

That's it... 1 AutoIt line and 1 CMD line. I need to use the AutoIt RUN command because I need to capture stdout and pipe it to the GUI.

Can anyone help with this?

By the way, this is on a WinXP Pro box using AutoIt 3.3.0.0.

Thanks!

Edited by Ciege

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Why not:

#include <Constants.au3>

Local $foo = Run(@ComSpec & " /c dir xcopy.exe c:\temp\*.au3 c:\*.au3", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$output=""
While 1
    $output &= StdoutRead($foo)
    If @error  Then ExitLoop
WEnd

MsgBox(0, "Output", $output)

[edit] yeah that ain't working... poking at it

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

What I gave was an example of the function failing not the actual XCOPYs I need to run.

I cannot use the method you describe (at this time) because I have inherited this system that has tens of CMD files with hundreds of XCOPYs.

At this point I need to just wrap the CMDs so I can get all of them to run in an automated fashion. It is not until a future time that I can convert all the CMDs into AutoIt code.

Make sense?

Share this post


Link to post
Share on other sites

gotcha


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

Odd... cant get any .bat or .cmd to function properly when calling it with run() they work fine from ShellExecute() but of course you cant use StdoutRead() with that.


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks for looking. I cannot get XCOPY to work through a CMD/BAT from AutoIt either. Copy and all other functions work but again I was hoping to just wrap functions at this time rather than rewrite existing, working CMDs. I'll have to noodle this a bit and see if I can come up with a solution that doesn't require the CMD rewrite/convert to AutoIt code yet.

Thanks,

Ciege...

Edited by Ciege

Share this post


Link to post
Share on other sites

Is anyone else able to help with this or can someone let me know how I need to go about submitting a bug report for this?

Thanks,

Ciege...

Share this post


Link to post
Share on other sites

This works for me

#include <Constants.au3>
$pid = Run(@ComSpec & " /c foo.cmd", "c:\", @SW_HIDE, BitOR($STDIN_CHILD, $STDOUT_CHILD, $STDERR_CHILD))
$Out = ""
$Err = ""
While 1
    $Out &= StdOutRead($pid)
    If @error Then ExitLoop
    $Err &= StdErrRead($pid)
    If @error Then ExitLoop
    sleep(10)   
Wend
ConsoleWrite("STDOUT: " & $Out & @LF & "ERROUT: " & $Err & @LF)

Share this post


Link to post
Share on other sites

Just to add to what picaxe said, it works for me too. I did a test running a batch file and also specifically running an xcopy bat file. This is what my xcopy bat looked like

@ECHO message 1

@ECHO message 2

@xcopy.exe "C:\Documents and Settings\me\Desktop\system.bat" "c:\"

the echos were just added to test.


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

Just to add to what picaxe said, it works for me too. I did a test running a batch file and also specifically running an xcopy bat file. This is what my xcopy bat looked like

@ECHO message 1

@ECHO message 2

@xcopy.exe "C:\Documents and Settings\me\Desktop\system.bat" "c:\"

the echos were just added to test.

or... you could read the .cmd files using FileOpen, FileReadLine, and parse each line like that? :)

Share this post


Link to post
Share on other sites

This works for me

#include <Constants.au3>
$pid = Run(@ComSpec & " /c foo.cmd", "c:\", @SW_HIDE, BitOR($STDIN_CHILD, $STDOUT_CHILD, $STDERR_CHILD))
$Out = ""
$Err = ""
While 1
    $Out &= StdOutRead($pid)
    If @error Then ExitLoop
    $Err &= StdErrRead($pid)
    If @error Then ExitLoop
    sleep(10)   
Wend
ConsoleWrite("STDOUT: " & $Out & @LF & "ERROUT: " & $Err & @LF)

This solved it! I Was not using the $STDIN_CHILD flag only $STDOUT_CHILD and $STDERR_CHILD. By adding the $STDIN_CHILD the xcopy worked fine. Interesting...

Thank you!

Ciege...

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