RAR file extract with password

Reply
New Contributor
Posts: 2

RAR file extract with password

Hi,

Does anyone knwo how to extract a file using RAR that is password protected.  I have the below code but this doesn't seem to work.

_null_ ;

unzipcmd='"C:\Program Files\WinRAR\RAR.exe" -min -e -o -s' ;

pw="a" ;

zipfile="H:\*.rar" ;

whereto='H:\test\*' ;

file='ae.sas7bdat' ;

cmd=unzipcmd || pw || ' ' || zipfile || ' ' || whereto || ' ' || file ;

putlog "NOTE-Processing command " cmd ;

call system( cmd ) ;

run ;

Thanks

James

Super User
Super User
Posts: 7,392

Re: RAR file extract with password

Hi,

Well, I don't have WinRAR installed so I can't check this, but I can see at least one error in the string you pass to system:

"C:\Program Files\WinRAR\RAR.exe" -min -e -o -sa H:\*.rar H:\test\* ae.sas7bdat

If you check out the command line parameters manual at:

WinRAR manual

You will see that a password should be supplied with the -p switch not the -s switch.  Also I think you have list of files and extract path swapped over.

I would recommend reading the guidance there and getting it to work in dos first.  Then once you have a string that works there, then reverse engineer that string in your SAS code.

Super User
Super User
Posts: 6,498

Re: RAR file extract with password

Use a PIPE instead of SYSTEM or X command so that you can retrieve any console messages your called program tried to generate.

data _null_;

  cmd = '.......';

  infile cmd pipe filevar=cmd end=eof ;

  input ;

  put _infile_;

run;

New Contributor
Posts: 2

Re: RAR file extract with password

Thanks Tom,

I'm fairly new to SAS and ripped the code from the internet, I'm not sure what you code does or how to make it work.

Can you provide a dumbies version?

Thanks

James

Super User
Super User
Posts: 6,498

Re: RAR file extract with password

Just put the command you want to run into the variable specified in the FILEVAR= option of the infile statement. The same as you tried to do in preparation for calling the SYSTEM( ) command.

For example to see a list of the RAR files on your drive the command could be "dir H:\*.rar".

data _null_;

  cmd = "dir H:\*.rar" ;

  infile dummy pipe filevar=cmd ;

  input ;

  put _infile_;

run;

If you only want to run one command and it does not require data step coding to construct the command then you can put the command where you would normally place the physical filename in the INFILE statement.

data _null_;

  infile "dir H:\*.rar" pipe ;

  input ;

  put _infile_;

run;

Ask a Question
Discussion stats
  • 4 replies
  • 4348 views
  • 0 likes
  • 3 in conversation