Sign in to follow this  
Followers 0
schilbiz

Simple StringFormat problem

14 posts in this topic

Hey guys, I have an issue with stringformat maybe someone can tell me whats going wrong with it.

This works, as it should.

$runstring = (@ComSpec & " /c " & 'copy C:\test\007.txt C:\test\C_M_F.txt')
Run($runstring)

Share this post


Link to post
Share on other sites



Have you tried MsgBox(0,"Runstring",$runstring) to see if it is even a valid run command?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Have you tried MsgBox(0,"Runstring",$runstring) to see if it is even a valid run command?

Actually yes I did and it spit out a bunch of garbled text. But it looked more like a graphical error then functional.

I have used StringFormat in the same way before and not had this issue. Are you implying that what it shows is exactly what it tries to run?

Edit: This is what it dispays: C:CINDOWSIystem32ymd.exe /c copy C:\test\007.txt C: este_M_F.txt

Edited by schilbiz

Share this post


Link to post
Share on other sites

Dude, have you even read the helpfile?? That's not how StringFormat works!!

Yes I read the helpfile almost everytime I code.

I have used StringFormat it in this manner in other scripts and it works fine, granted there is more to it that what I am trying now. Here is an example function taken out of a larger script on how I got it to work before.

Func PROCESS()
    Local $line
    $r_Machine = GUICtrlRead($I_Machine)
    $r_User = GUICtrlRead($User_I)
    $r_Pass = GUICtrlRead($Pass_I)


   $runString = StringFormat("tasklist /s %s /u %s /p %s /fo csv /nh", $r_Machine, $r_User, $r_Pass) 
   $run = Run($runString, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

    
While 1
        $line &= StdoutRead($run)
        If @error Then ExitLoop
    WEnd
    While 1
        $line &= StderrRead($run)
        If @error Then ExitLoop
        MsgBox(0, "Error: Try again...", "Invalid Process or no Process selected.", 3)
        Return
    WEnd

Share this post


Link to post
Share on other sites

You are getting me feel very uncertain now.... I think I will retreat for the moment. :P

As an example run this:

$r_Machine = "Machine"
    $r_User = "Username"
    $r_Pass = "Password"
    $runString = StringFormat("tasklist /s %s /u %s /p %s /fo csv /nh", $r_Machine, $r_User, $r_Pass)
    MsgBox(0,"Runstring",$runstring)

You will notice that it is accurate.

Share this post


Link to post
Share on other sites

Try doing something like:

$runstring = @ComSpec & " /c " & StringFormat('copy %s C:\test\C_M_F.txt', $sFile1)
MsgBox(0,"Runstring",$runstring)

My guess is that @ComSpec isn't being parsed properly because of:

Online Docs: value of %comspec%, the SPECified secondary COMmand interpreter; primarily for command line uses, e.g. Run(@ComSpec & " /k help | more")

Which means %c and % in %comspec% might be the culprit. Since StringFormat might be taking it literally.

-CMR

Share this post


Link to post
Share on other sites

Try doing something like:

$runstring = @ComSpec & " /c " & StringFormat('copy %s C:\test\C_M_F.txt', $sFile1)
MsgBox(0,"Runstring",$runstring)

My guess is that @ComSpec isn't being parsed properly because of:

Online Docs: value of %comspec%, the SPECified secondary COMmand interpreter; primarily for command line uses, e.g. Run(@ComSpec & " /k help | more")

Which means %c and % in %comspec% might be the culprit. Since StringFormat might be taking it literally.

-CMR

Interesting, that seems like it is on the right track, that output looked like this:

C:\Windows\system32\cmd.exe /c copy C:\test\007.txt C: este_M_F.txt

That gives me a few ideas though, I will play with it some more.

Thanks.

Share this post


Link to post
Share on other sites

Wierd. Maybe a bug in StringFormat?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Wierd. Maybe a bug in StringFormat?

No Bug,

It states in the Helpfile:

"Remarks

To prevent buffer overflow, each "variable" is limited to 65535 characters.

Escape characters can be contain in the "format control" such as \n (@LF), \r (@CR), \t (@TAB]. So if you want to have a "\" you need to use \\, samething for "%" %%.

"variable format" is; %[flags] [width] [.precision] type"

So I just had to alter it a little, and now it works.

$sFile1 = "C:\test\007.txt"
$runstring = @ComSpec & " /c " & 'copy ' & StringFormat('%s ' &  "C:\\test\\C_M_F.txt", $sFile1)
MsgBox(0,"Runstring",$runstring)

Odd that the \'s in $sFile1 do not trigger the same garbled error. It looks ugly but it works. Thanks for the help.

Edited by schilbiz

Share this post


Link to post
Share on other sites

Why aren't you just using FileCopy()?

Share this post


Link to post
Share on other sites

Why aren't you just using FileCopy()?

I plan on copying multiple large 500+(MB) files into 1 file and filecopy does not seem to allocate the memory very well and errors out. The only thing that I could get to work is this:

Run(@ComSpec & " /c " & 'copy C:\test\*.txt C:\test\C_M_F.txt', "", @SW_HIDE) ; this will copy multiple *.txt files to the one file, fast and easy.

I am not entirely sure why it works but it can allocate 1.5 GB of files and copy it without erroring out. I remember back in DOS it did manage copying files etc better than Windows does. On this computer I have 1GB RAM with Page File of max 2048 so there technically should be plenty of "Memory" available.

Do you know of a better way?

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Granted I know that command prompt "copy" is not a DOS command in Windows XP. It does somehow manage memory better than FileCopy, if someone knows why please explain.

For example:

I have 5 .txt files that I need to merge into 1 large file.

File1 307mb

File2 519mb

File3 519mb

File4 519mb

File5 1.8gb

When I run the below code it instantly copies the 307mb file over, then hangs and the script ends. It doesn't even get to File2.

FileCopy("C:\test\sfile\*.txt", "C:\test\C_M_F.txt")oÝ÷ Ùh^îØ^méhÁÊz+¢±©e¡ûayø¥zÊ/z»h¶§{âéhq«b¢x§r·¦z{ZÙ²ºÇ=¨)^ëÞ®
±¦èºÞ¸òfß®®§w®6»-j»b  ^½éHµÊ)ë-çâë(½êÚ×+^±¨níû·âì"¶.µªk¡¹^«­¢+ØÀÌØíÍ¥±ÄôÅÕ½ÐíèÀäÈíÑÍÐÀäÈíÍ¥±ÀäÈ쨹ÑáÐÅÕ½Ðì(ÀÌØíÉÕ¹ÍÑÉ¥¹ô
½µMÁµÀìÅÕ½Ðì½ÅÕ½ÐìµÀìMÑÉ¥¹½ÉµÐ Ìäí½ÁäÌèÀäÈìÀäÈíÑÍÐÀäÈìÀäÈí
}5}¹ÑáÐÌäì°ÀÌØíÍ¥±Ä°M]}!%¤(í5Í  ½à À°ÅÕ½ÐíIÕ¹ÍÑÉ¥¹ÅÕ½Ðì°ÀÌØíÉÕ¹ÍÑÉ¥¹¤)IÕ¸ ÀÌØíÉÕ¹ÍÑÉ¥¹¤

Edit: Added the example.

Edited by schilbiz

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